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 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.
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).
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.
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)
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.
Comments (47) 14 threads
Earlier comments> 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 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.
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).
(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.
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.
Unfortunately since then most wins haven’t been nearly as dramatic, but still a happy user of flame graphs.
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.
Continue this thread — 3 replies
Continue this thread — 1 reply
But everything usually looks fine on local env, and can’t really replicate the intricacies of prod locally. How do you guys do it?
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
All comments shown.
Couldn't load more comments. Check your connection and try again.