Skip to content

Commit

Permalink
Aggressively purge video data when its unused (#7592)
Browse files Browse the repository at this point in the history
### What

Before, we'd only remove `re_video` objects on memory purges. With this
change we do it immediately when a video is unused for a frame.
Empirically that's the better strategy given that we're already purging
decoders eagerly (which we have to do pretty much because we create new
ones for every little preview) since it takes a lot longer to get decode
a video than it takes to parse the mp4.



https://github.com/user-attachments/assets/2a841caa-6c7b-4651-ac84-d91135ca9989
  • Loading branch information
Wumpf authored Oct 7, 2024
1 parent 5da39a5 commit d03631d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/viewer/re_viewer_context/src/cache/video_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ impl VideoCache {

impl Cache for VideoCache {
fn begin_frame(&mut self, renderer_active_frame_idx: u64) {
// Clean up unused video data.
self.0.retain(|_row_id, per_key| {
per_key.retain(|_, v| v.used_this_frame.load(Ordering::Acquire));
!per_key.is_empty()
});

// Of the remaining video data, remove all unused decoders.
for per_key in self.0.values() {
for v in per_key.values() {
v.used_this_frame.store(false, Ordering::Release);
Expand All @@ -80,10 +87,13 @@ impl Cache for VideoCache {
}

fn purge_memory(&mut self) {
self.0.retain(|_row_id, per_key| {
per_key.retain(|_, v| v.used_this_frame.load(Ordering::Acquire));
!per_key.is_empty()
});
// We aggressively purge all unused video data every frame.
// The expectation here is that parsing video data is fairly fast,
// since decoding happens separately.
//
// As of writing, in a debug wasm build with Chrome loading a 600MiB 1h video
// this assumption holds up fine: There is a (sufferable) delay,
// but it's almost entirely due to the decoder trying to retrieve a frame.
}

fn on_store_events(&mut self, events: &[ChunkStoreEvent]) {
Expand Down

0 comments on commit d03631d

Please sign in to comment.