Re:Optimizing a Math Expression Parser in Rust
by erk__ on Thursday July 10, 2025 @10:07AM
(#44521284)
It should be noted that even though the post links to the perl version for some reason, it is actually not what cargo flamegraph [0] uses, it uses a reimplementation of it in Rust called inferno [1].
Re:Optimizing a Math Expression Parser in Rust
by IshKebab on Thursday July 10, 2025 @12:19PM
(#44522662)
Ah interesting. It seems to be no better than the Perl one though, except not requiring Perl. It's still a static SVG.
Re:Optimizing a Math Expression Parser in Rust
by porphyra on Thursday July 10, 2025 @01:46PM
(#44523565)
It's not a static SVG though. The SVG supports interactivity. You can click on each element to zoom in and it even has a search feature.
Re:Optimizing a Math Expression Parser in Rust
by IshKebab on Thursday July 10, 2025 @02:05PM
(#44523801)
Ah really? Their example here doesn't do that: https://github.com/jonhoo/inferno/blob/main/tests/data/flame...
But even so, pprof's is better. (You'll have to try it or take my word for it; they don't seem to have a demo anywhere unfortunately.)
When you hover a function it highlights all the other calls to that function (in different stacks), and if you click it it shows all the calls to and from that function in all stacks with two-sided flame graph.
Re:Optimizing a Math Expression Parser in Rust
by porphyra on Thursday July 10, 2025 @02:16PM
(#44523916)
The one at https://github.com/flamegraph-rs/flamegraph/blob/main/exampl... supports both zooming and search.
Re:Optimizing a Math Expression Parser in Rust
by IshKebab on Thursday July 10, 2025 @05:41PM
(#44525931)
Ah I see. Yeah pprof is significantly superior.
Re:Optimizing a Math Expression Parser in Rust
by ivanjermakov on Thursday July 10, 2025 @08:11PM
(#44527120)
Also Jon streamed the process of porting flamegraph to Rust: https://youtu.be/jTpK-bNZiA4?si=VsvBln60BCEU7hbz
Re:Optimizing a Math Expression Parser in Rust
by jdreaver on Thursday July 10, 2025 @10:55AM
(#44521815)
I recently discovered that `perf` itself can spit out flamegraphs. My workflow has been:
$ perf record -g -F 99 ./my-program
$ perf script report flamegraph
You can also run `perf script -F +pid > out.perf` and then open `out.perf` in Firefox's built-in profile viewer (which is super neat) https://profiler.firefox.com
Re:Optimizing a Math Expression Parser in Rust
by the-wumpus on Thursday July 10, 2025 @10:16AM
(#44521374)
pprof doesn't do an amazing job of explaining how to use it with perf (which you'd need to use for a rust project like OP), so:
First install perf, graphviz, perf_data_converter and ofc pprof, then generate the data with `perf record [command]`, and display it with `pprof -http=: perf.data`.
Re:Optimizing a Math Expression Parser in Rust
by IshKebab on Thursday July 10, 2025 @11:33AM
(#44522168)
I typically use gperftools for profiling instead of perf. You can LD_PRELOAD it.
Re:Optimizing a Math Expression Parser in Rust
by remram on Thursday July 10, 2025 @10:16AM
(#44521384)
That repo has no builds and no releases, kind of surprising? And needs another tool to consume perf data?
edit: And I can only build it using bazel, and I need bazel to build bazel? I think I'll stick with Perl...
Re:Optimizing a Math Expression Parser in Rust
by IshKebab on Thursday July 10, 2025 @11:35AM
(#44522188)
I guess you didn't get very far in the README because near the top it tells you how to install it. It's a single command:
go install github.com/google/pprof@latest
Use the Go version of pprof: https://github.com/google/pprof
Run it like `pprof -http : your_profile.out` and it will open a browser with a really nice interactive flamegraph (way better than the Perl version), plus a call graph, source line profiling, top functions, etc. etc.
It's so much better. Don't use the Perl version. I should probably write a post showing how to do this.
Another also-much-better alternative is Samply (https://github.com/mstange/samply) which uses the Firefox Profiler as a GUI. I don't like it quite as much as pprof but it's clearly still much better than what's in this article:
https://share.firefox.dev/3j3PJoK