Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DriveMap: fixed high CPU usage during idling #515

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

vishalkrishnads
Copy link
Contributor

Fixes #378. The CPU usage was due to the following lines of code being executed unnecessarily within the map component's updateMarkerPos() method:

updateMarkerPos() {
    // ..
        markerSource.setData({
            type: 'Point',
            coordinates: pos,
          });
          if (!this.isInteracting) {
            this.moveViewportTo(pos);
          }
    // ...
}

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.

Copy link

github-actions bot commented Jun 19, 2024

Welcome to connect! Make sure to:

  • read the contributing guidelines
  • mark your PR as a draft until it's ready to review
  • post the preview on Discord; feedback from users will speedup the PR review

deployed preview: https://515.connect-d5y.pages.dev

@sshane
Copy link
Contributor

sshane commented Jun 20, 2024

If the CPU usage is especially egregious we can also decimate, but that's for another PR.

@incognitojam incognitojam changed the title fixed high CPU usage during idling DriveMap: fixed high CPU usage during idling Jun 21, 2024
@incognitojam incognitojam merged commit 112d624 into commaai:master Jun 21, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

high CPU usage idling on drive video page
3 participants