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.
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?
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.
Flame graphs alone justify the worship, found a hot regex in our billing service in ten minutes
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.
Any loop is the prime suspect for optimization. I’ve seen a lot of naive implementation of something instead of using standard algorithms.
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.
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?
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.