DriveMap: fixed high CPU usage during idling #515
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #378. The CPU usage was due to the following lines of code being executed unnecessarily within the map component's
updateMarkerPos()
method:I noticed this when I profiled the component with react's
<Profiler />
. The map was constantly re-rendering even with the video paused. Logically, the only reason that map would want to re-render all the time would be to update the marker position according to the video. But, this was happening when the video was paused as well.In order to update the marker position in real time, the map consumes CPU. This is fine, but the bottleneck arises when the map keeps updating the marker even while the video is idle. To fix this, I simply introduced a check. If the last position of the marker hasn't changed, then don't re-render it. This has fixed the high CPU usage when the video is paused or in other words, the page is idle.