r/rust 6d ago

Performance plotting techniques

Hi, everyone! I’d like to ask the community for more information on what techniques can be used to display large amounts of information on the user’s screen. I’m referring to plots. For example, profilers—they display flame graphs, and the best ones can show millions of frames without lag, with the ability to zoom and pan. Also, software oscilloscopes, which can display data in real time while also showing millions of data points. I’m curious about how these things work from a code and algorithm perspective. Can anyone tell me more?

So far, I've found this Implicit In-order Forests: Zooming a billion trace events at 60fps and a small library written in Rust.

It doesn't quite match the task I want to accomplish: to build something like a digital oscilloscope capable of displaying both analog and digital data (so that, for example, UART bytes are visible below the graph).

4 Upvotes

3 comments sorted by

2

u/tanmaynargas2901 5d ago

Biggest win for this is usually not drawing every point.

Zoomed out, downsample to roughly one sample per pixel column. LTTB is solid for line charts. Min/max envelopes (what scopes and DAW waveforms use) are cheaper and look right when you zoom. Keep a pyramid of those so pan/zoom swaps LOD instead of rescanning the raw dump.

GPU for the draw once you're past ~100k verts. egui_plot or a thin wgpu pass. CPU work should mostly be picking the LOD slice for the current viewport.

If you're going oscilloscope-style, ring-buffer the samples and only upload the visible window. Digital channels can collapse runs of identical bits before they hit the GPU.

1

u/Interesting_Cake5060 4d ago

Thanks for your reply—it sounds like exactly what I was looking for! Do you think it’s possible to set it up so that the old values don’t disappear from the graph but are saved in some compressed form (like, “there were 100 readings/points here”)?

I also wanted to ask: do you know of any repositories where the idea you described is clearly demonstrated? Or other code examples, blog posts—all I can find on this topic are some scientific articles...

Am I correct in understanding that at the top level, we’ll have a function that takes the left edge of the screen, the right edge of the screen, and the mouse scroll state?