Skip to content

Commit

Permalink
Optimize cloning/sorting/deduplication of frames
Browse files Browse the repository at this point in the history
This update modifies the data containers used for storing frames to
adopt binary tree structures. As a result, all frames are sorted at the
time of insertion, eliminating the need for subsequent sorting during
vector collection.

Moreover, instead of returning vectors, the binary tree structure
enables iteration over elements in a sorted order, providing iterators
rather than vectors. This functionality gives the API caller the
flexibility to either clone frames or simply inspect them in an
efficient manner.
  • Loading branch information
andreiltd committed Jun 22, 2023
1 parent 0a80c56 commit 7eacaf9
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 124 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions puffin-imgui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl ProfilerUi {
let view = self.frame_view.lock();
Frames {
recent: view.recent_frames().cloned().collect(),
slowest: view.slowest_frames_chronological(),
slowest: view.slowest_frames_chronological().cloned().collect(),
}
}

Expand Down Expand Up @@ -392,10 +392,17 @@ impl ProfilerUi {
}

fn all_known_frames(&self) -> Vec<Arc<FrameData>> {
let mut all = self.frame_view.lock().all_uniq();
let mut all = self
.frame_view
.lock()
.all_uniq()
.cloned()
.collect::<Vec<_>>();

if let Some(paused) = &self.paused {
all.append(&mut paused.frames.all_uniq());
}

all.sort_by_key(|frame| frame.frame_index());
all.dedup_by_key(|frame| frame.frame_index());
all
Expand Down
1 change: 1 addition & 0 deletions puffin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ web = ["instant/wasm-bindgen", "dep:js-sys"]
byteorder = { version = "1.0" }
cfg-if = "1.0"
instant = { version = "0.1" }
itertools = "0.10"
once_cell = "1.0"

# Optional:
Expand Down
Loading

0 comments on commit 7eacaf9

Please sign in to comment.