Skip to content

Commit 15e131c

Browse files
committed
Fix overhead measures based on real-life data
1 parent 3e569df commit 15e131c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn my_function() {
3030
}
3131
```
3232

33-
The Puffin macros write data to a thread-local data stream. When the outermost scope of a thread is closed, the data stream is sent to a global profiler collector. The scopes are pretty light-weight, costing around 60 ns on an M1 MacBook Pro.
33+
The Puffin macros write data to a thread-local data stream. When the outermost scope of a thread is closed, the data stream is sent to a global profiler collector. The scopes are pretty light-weight, costing around 50-200 ns.
3434

3535
You have to turn on the profiler before it captures any data with a call to `puffin::set_scopes_on(true);`. When the profiler is off the profiler scope macros only has an overhead of 1 ns on an M1 MacBook Pro (plus some stack space).
3636

puffin_egui/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,17 @@ impl ProfilerUi {
533533
let frame = frames.frames.first();
534534

535535
let num_scopes = frame.meta.num_scopes;
536-
let overhead_ms = num_scopes as f64 * 50.0e-6; // Around 50 ns per scope on an Apple M1.
537-
if overhead_ms > 0.5 {
536+
let realistic_ns_overhead = 200.0; // Micro-benchmarks puts it at 50ns, but real-life tests show it's much higher.
537+
let overhead_ms = num_scopes as f64 * 1.0e-6 * realistic_ns_overhead;
538+
if overhead_ms > 1.0 {
539+
let overhead = if overhead_ms < 2.0 {
540+
format!("{:.1} ms", overhead_ms)
541+
} else {
542+
format!("{:.0} ms", overhead_ms)
543+
};
544+
538545
let text = format!(
539-
"There are {num_scopes} scopes in this frame, which adds up to ~{overhead_ms:.1} ms of overhead.\n\
546+
"There are {num_scopes} scopes in this frame, which adds around ~{overhead} of overhead.\n\
540547
Use the Table view to find which scopes are triggered often, and either remove them or replace them with profile_function_if!()");
541548

542549
ui.label(egui::RichText::new(text).color(ui.visuals().warn_fg_color));

0 commit comments

Comments
 (0)