Yea, I love being able to go from the new guy at a new job straight to the performance wizard in the first week, or even on the first day. It’s so fun to stare into the depths of a flamechart and then point out where the problems are.
At one job they had built this whole nifty SQL library and used it everywhere. In the first profile I took I saw that repeatedly preparing a query took more time than running it and using the data. Each call to prepare took the same amount of time as the others, so it was obvious at a glance that they weren’t caching and reusing the results. The documentation said that they did, and their tests all worked, so they had used it for years even though it was fundamentally broken. That was a fun week.
When I worked at Microsoft, I found a particular hot function using flame graphs in a C++ application covering roughly 50% of all call paths in some runs. It was the constructor for a hand-rolled map-like data structure that was used all over the app. Switching to IIRC an abseil hash map cut the overhead by something like 98%. The app was a simulation-type thing that ran on a server for millions of cycles and runs dropped from something like 2 hours to 1 hour, as you’d expect.
Unfortunately since then most wins haven’t been nearly as dramatic, but still a happy user of flame graphs.
Do you really need flame graphs for that? Wouldn't any normal profiler tell you if a function and its children used 50% of your CPU?
I always struggle to see why people think flame graphs are so great, but I'm not sure if people are comparing them to a normal (non-graphical) profile or not.
Flamegraphs sort the samples by location, rather than ordered by time. They also show hierarchy, rather than just leafs. All combinations on those two axis can be useful to present. Strictly speaking a normal profiler is probably one that gives leaf calls only in order, which is probably the least useful quadrant, but the fastest to generate (works better for hand annotated events and to see latency rather than time)
> Flamegraphs sort the samples by location, rather than ordered by time.
I'm not sure if I understand. Do you mean ordered by amount of time spent, or by event time in the executable? (Most profilers do the former, and flame graphs are implicitly a variant of that by scaling the blocks visually by execution time.)
> They also show hierarchy, rather than just leafs.
Like any profiler in graph mode? Every profiler I've used over the last 20 years (even gprof!) can show function hierarchy, both top-down and bottom-up.
Event time. It's a common mode for profilers that are looking at latency. And yes, any profiler in call stack mode is the same data, just without the colorful visuals, as he talked about in the intro paragraph: https://www.brendangregg.com/flamegraphs.html
Probably could have done it without flame graphs, but the flame graphs made the problem incredibly obvious to anyone including non programmers. I was not originally on the project to work on performance per se, so I had to justify the work.
CPU/SoC performance modeling. It probably had a side effect of stress testing azure compute though. And yes, the irony of a performance modeling tool having terrible performance wasn’t lost on me. (Probably a result of the app mostly being written by people with a hardware engineering background, not software.)
I struggle with measuring performance. I cannot run such tools in prod envs. Not even in dev envs, only locally. This is because only platform engs have prod access.
But everything usually looks fine on local env, and can’t really replicate the intricacies of prod locally. How do you guys do it?
They should still be able to provide you with traces from prod even if you can't directly access the systems. Most of perf work is analyzing, not collecting.
You can collect profiles from your production environment using some sort of continuous profiler, like Grafana Alloy or the OTel profiler. We actually built https://github.com/yandex/perforator specifically to profile everything we can reach.
This thing also greatly helps when exploring unfamiliar codebases. You can just open a flame graph in a few clicks and see what the program actually does.
scripts got significantly faster using isoformat for parsing date times over str. These were critical recovery/startup scripts for an ultra low latency
no one ever bothered to look. a profile found it instantly
I don't usually worship much, but I must admit flame graphs have had a huge influence on my work. I've used them creatively for other things than performance analysis.
Here is my small contribution to the altar though : 3d flame graphs :)
Determinism is the underrated part of all this. For a Python framework I maintain we moved the CI benchmarks to Callgrind: instruction counts instead of time, with the cache geometry pinned so it doesn't matter which runner you land on. The numbers basically stopped moving between runs, which wall-clock never gave us on shared runners. The catch is that you lose everything off-CPU, which is exactly what this post is about, so the critical path view is a bit enviable.
(It's fine, of course, to use AI tools—we use them heavily ourselves. Just please don't use them to generate or edit text to be read by fellow humans on Hacker News.)
It's impossible to know for sure what was LLM generated or edited, but we have to rely on imperfect classifiers or else the site would be completely flooded by genai text, which is not what the community here wants to read, nor in the intended spirit of HN.
On a live machine you have to start tracing before the slow run happens, and tracing has a cost, so you only get a few attempts. Here every recording already logs every context switch because the VM needs them to replay, so the off-CPU and wakeup analysis can be done afterwards, on any run. The hrtime test is a useful distinction too: it accounts for 3.38s of the critical path, but the sleep is intentional, so the drag you can actually remove is zero.
I really like the idea of a deterministic VM (I like Antithesis for a similar reason!), though I saw on another post that your VM is single threaded which I feel like must compromise a lot of performance analyses? E.g. when you have very high throughput multithreaded pipelines.
Personally I've really cooled on flamegraphs for the purpose of doing multithreaded performance analysis - it's so hard to infer cross-thread dependencies. I'd encourage people interested in performance analysis to read https://thume.ca/2023/12/02/tracing-methods/ (and I'd love to hear if there's something more recent than end of 2023 that has an updated census of tools) which makes a decent case for perfetto, though in my own use-cases I've just ended up creating low latency language-specific trace output library that I can aggregate and load into jaeger-ui, as you can actually add metadata indicating spans you follow from etc.
For the author: your product looks very cool, but I encourage you (or someone you pay!) to do an extensive proof reading pass to remove LLM-isms, reading stuff like "process, with what it started" as a column header of ps-like output is like nails on a chalkboard.
> I really like the idea of a deterministic VM (I like Antithesis for a similar reason!)
I agree, and I also like Antithesis, but I am a bit dismayed that deterministic high-performance VMs haven't become commodity yet.
I know, I know, I am impatient, and it will happen eventually, but it's frustrating to see Antithesis corner the market so hard with a closed solution.
Maybe this is a sign I should start yet another side project?
Does this type of analysis and deterministic VM help async workloads (e.g. c++ coroutine, fiber, future, etc.)? My understanding is that they don't. I would love to know how to find the critical path for async code. It feels very hard (maybe impossible) to do without changing the framework code (e.g. embedding something like a request context so we know a later task on thread A is actually a continuation for request R).
I see. I am not familiar with deterministic VMs. I can see how it can intercept all system calls. I guess randomness is deterministic as well because all the inputs to the RNG are deterministic. So everything is a deterministic state machine.
> Give a CPU the same registers, the same memory and the same instructions, and it computes the same result.
So is branch prediction, cacheline misses, memory accesses I guess.
> One more outside influence is easy to miss: other CPUs. On two cores, which thread wins a race comes down to cache misses and pipeline stalls, so Rewind provides a single virtual CPU and the threads take turns on it.
Is this a limitation in practice? With a single virtual cpu, data races simply can't happen?
Everything they described about their runtime is just a time travel debugger using a single-threaded record and replay model. So yes.
Their visualizations are techniques based around leveraging the extra data available in a full instruction trace. As such, they can be applied to any time travel debugger datastream, which trivially has a full instruction trace, or just raw instruction trace if that is all you have.
[rr maintainer here]. Similar principles but there are important differences. rr records and replays user-space processes and has to understand the user/kernel interface really well, which is a problem because that interface is super complicated. RewindVM replays the whole VM, simplifying the interface because the hypervisor interface is (or at least, can be configured to be) somewhat simpler than the user/kernel interface. The overhead of replaying at the VM level will be different ... possibly lower, possibly higher, depending on the workload; you might expect there to be fewer VM exits than system call traps, but OTOH you have to record and replay the entire guest OS instead of specific processes.
In terms of functionality, they're different. rr supports arbitrary timeslicing, e.g. thread switches at any program instruction, which ReplayVM does not. RewindVM depends on Nix, rr doesn't. RewindVM supports a kind of "mutable replay" where you can resume a VM from a checkpoint and cause it to do something different from what was previously recorded; rr's version of that is much more limited.
sadly the answer to the investigation was just a footnote.
> 4 Turns out that the test sleeps on purpose: it is checking how far uv_hrtime moves across a sleep. There is nothing to optimize in this case.
also, no explanation of why he didn't look into the epoll_wait(). i guess because this is a blocking call, not intentionally asleep, and also the intentional sleep is magnified 600 times? epoll_wait() shows up as consuming 3x of the wall time but in the shortening analysis the nanosleeps are shown to add up to more time asleep. i'm a little confused on that.
good article, would have been great with more editing. and it would be great to also see an example where a problem is fixed.
I only looked at the first bug you list on the bugs.html page, and it doesn't appear to have needed or used the `time` tool. As this article is specifically about the `time` functionality, that's what I was complaining was missing from your article. Maybe that was an unfair complaint, as I can't find a single example on the internet (using Gregg's tooling, which has existed forever).
A co-worker (formally of Nvidia) recently explained to us (his new company) Nvidia's cultural "speed of light" idea.
The core idea is you don't ask "is our GPU (or whatever is being built) as fast as the last one?" You don't even ask "is it as good as any GPU ever made?"
You instead ask "is it as fast as the speed of light?"
In other words, if you just waved away everything slowing you down, what's the absolute fastest you could complete your task? ONLY once you know that can you start putting back the other factors that slow you down: first you must start by comparing to the fastest possible way things could be ("speed of light").
Curiously enough I reached the same mentality while doing performance optimizations in university. At some point you realize performance optimization is just trimming away fat you didn't actually need. This means there's a lean muscle mass somewhere that's absolutely necessary and you can't do [the thing] without it. That's essentially the only computation required to implement the feature. Everything else is fat.
Sure, sometimes fat is good. Fat is compromise. Fat might be orthogonal concerns. But you'll never get leaner than that essential muscle mass.
I guess in their case "speed of light" is the leanest muscle mass required.
Replies (5)
At one job they had built this whole nifty SQL library and used it everywhere. In the first profile I took I saw that repeatedly preparing a query took more time than running it and using the data. Each call to prepare took the same amount of time as the others, so it was obvious at a glance that they weren’t caching and reusing the results. The documentation said that they did, and their tests all worked, so they had used it for years even though it was fundamentally broken. That was a fun week.
Replies (1)
Unfortunately since then most wins haven’t been nearly as dramatic, but still a happy user of flame graphs.
Replies (2)
I always struggle to see why people think flame graphs are so great, but I'm not sure if people are comparing them to a normal (non-graphical) profile or not.
Replies (2)
Replies (2)
I'm not sure if I understand. Do you mean ordered by amount of time spent, or by event time in the executable? (Most profilers do the former, and flame graphs are implicitly a variant of that by scaling the blocks visually by execution time.)
> They also show hierarchy, rather than just leafs.
Like any profiler in graph mode? Every profiler I've used over the last 20 years (even gprof!) can show function hierarchy, both top-down and bottom-up.
Replies (1)
I tried to combine both orientations in a 3d visualization here:
https://github.com/pcdv/mountain-graph
Replies (1)
Replies (1)
But everything usually looks fine on local env, and can’t really replicate the intricacies of prod locally. How do you guys do it?
Replies (2)
This thing also greatly helps when exploring unfamiliar codebases. You can just open a flame graph in a few clicks and see what the program actually does.
no one ever bothered to look. a profile found it instantly
Here is my small contribution to the altar though : 3d flame graphs :)
https://github.com/pcdv/mountain-graph
Replies (1)
Replies (1)
(It's fine, of course, to use AI tools—we use them heavily ourselves. Just please don't use them to generate or edit text to be read by fellow humans on Hacker News.)
It's impossible to know for sure what was LLM generated or edited, but we have to rely on imperfect classifiers or else the site would be completely flooded by genai text, which is not what the community here wants to read, nor in the intended spirit of HN.
Replies (1)
^1: https://xkcd.com/1053/
Replies (2)
Personally I've really cooled on flamegraphs for the purpose of doing multithreaded performance analysis - it's so hard to infer cross-thread dependencies. I'd encourage people interested in performance analysis to read https://thume.ca/2023/12/02/tracing-methods/ (and I'd love to hear if there's something more recent than end of 2023 that has an updated census of tools) which makes a decent case for perfetto, though in my own use-cases I've just ended up creating low latency language-specific trace output library that I can aggregate and load into jaeger-ui, as you can actually add metadata indicating spans you follow from etc.
For the author: your product looks very cool, but I encourage you (or someone you pay!) to do an extensive proof reading pass to remove LLM-isms, reading stuff like "process, with what it started" as a column header of ps-like output is like nails on a chalkboard.
Replies (1)
I agree, and I also like Antithesis, but I am a bit dismayed that deterministic high-performance VMs haven't become commodity yet.
I know, I know, I am impatient, and it will happen eventually, but it's frustrating to see Antithesis corner the market so hard with a closed solution.
Maybe this is a sign I should start yet another side project?
Replies (1)
Replies (1)
Replies (1)
Replies (1)
Replies (1)
> Give a CPU the same registers, the same memory and the same instructions, and it computes the same result.
So is branch prediction, cacheline misses, memory accesses I guess.
> One more outside influence is easy to miss: other CPUs. On two cores, which thread wins a race comes down to cache misses and pipeline stalls, so Rewind provides a single virtual CPU and the threads take turns on it.
Is this a limitation in practice? With a single virtual cpu, data races simply can't happen?
Replies (1)
But they involve a trade-off in the Linux kernel or spending more transistors in CPU design.
https://github.com/rr-debugger/rr
Replies (2)
Their visualizations are techniques based around leveraging the extra data available in a full instruction trace. As such, they can be applied to any time travel debugger datastream, which trivially has a full instruction trace, or just raw instruction trace if that is all you have.
In terms of functionality, they're different. rr supports arbitrary timeslicing, e.g. thread switches at any program instruction, which ReplayVM does not. RewindVM depends on Nix, rr doesn't. RewindVM supports a kind of "mutable replay" where you can resume a VM from a checkpoint and cause it to do something different from what was previously recorded; rr's version of that is much more limited.
> 4 Turns out that the test sleeps on purpose: it is checking how far uv_hrtime moves across a sleep. There is nothing to optimize in this case.
also, no explanation of why he didn't look into the epoll_wait(). i guess because this is a blocking call, not intentionally asleep, and also the intentional sleep is magnified 600 times? epoll_wait() shows up as consuming 3x of the wall time but in the shortening analysis the nanosleeps are shown to add up to more time asleep. i'm a little confused on that.
good article, would have been great with more editing. and it would be great to also see an example where a problem is fixed.
Replies (1)
I wanted the article to be more about the idea and performance investigation rather than about this one bug though.
With this much insight, lots of software has lots of bugs.
Replies (1)
I only looked at the first bug you list on the bugs.html page, and it doesn't appear to have needed or used the `time` tool. As this article is specifically about the `time` functionality, that's what I was complaining was missing from your article. Maybe that was an unfair complaint, as I can't find a single example on the internet (using Gregg's tooling, which has existed forever).
The core idea is you don't ask "is our GPU (or whatever is being built) as fast as the last one?" You don't even ask "is it as good as any GPU ever made?"
You instead ask "is it as fast as the speed of light?"
In other words, if you just waved away everything slowing you down, what's the absolute fastest you could complete your task? ONLY once you know that can you start putting back the other factors that slow you down: first you must start by comparing to the fastest possible way things could be ("speed of light").
Similar idea here.
Replies (1)
Sure, sometimes fat is good. Fat is compromise. Fat might be orthogonal concerns. But you'll never get leaner than that essential muscle mass.
I guess in their case "speed of light" is the leanest muscle mass required.
https://www.youtube.com/watch?v=tDacjrSCeq4