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

replay/framereader: no longer cache all AVPacket instances in memory #32236

Merged

Conversation

deanlee
Copy link
Contributor

@deanlee deanlee commented Apr 17, 2024

Caching all AVPacket instances in memory can simplify the seeking to a specific frame, but it consumes significant memory resources, limits the scalability of the FrameReader. especially when caching a greater number of segments in Replay or Cabana. it can lead to increased memory usage, potentially causing performance issues or even system instability if memory resources are exhausted.

This PR only stores the pkt_pos of each frame in memory. it uses avio_seek to seek to the frame's position, greatly reducing the memory footprint of FrameReader. It saves nearly 100MB of memory per segment for the road camera, with even greater savings when playing multiple cameras.

It will be slightly slower than caching all AVPacket in memory, but since we have implemented frame prefetching in the camera thread, the performance gap is negligible.

Copy link
Contributor

github-actions bot commented Apr 17, 2024

Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • the change is something we merge
    • include a route or your device' dongle ID if relevant

@github-actions github-actions bot added the tools label Apr 17, 2024
@deanlee deanlee marked this pull request as draft April 17, 2024 16:33
@deanlee deanlee force-pushed the framereader_reduce_memory_usage branch from d649c62 to ce50e56 Compare April 17, 2024 16:38
@deanlee deanlee marked this pull request as ready for review April 17, 2024 16:50
@adeebshihadeh adeebshihadeh merged commit 8124ba5 into commaai:master Apr 17, 2024
26 checks passed
@deanlee deanlee deleted the framereader_reduce_memory_usage branch April 17, 2024 17:35
cydia2020 pushed a commit to cydia2020/dodgypilot that referenced this pull request May 14, 2024
Edison-CBS pushed a commit to Edison-CBS/openpilot that referenced this pull request Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants