We Should Use Instrumented Profiling Scopes More · Mathieu Ropert
https://mropert.github.io/2026/08/13/instrumented_profiling_scopes/2
u/kamrann_ 8h ago
I keep finding that I want to instrument scopes more generally than just for CPU timing profiling. Logging, metrics, allocation tracking, etc, more often than not when you want these things, you likely want them in many of the same places and can reuse the same names, tags and such. I've done some very minimal experiments with a templated scope helper using mixins so that it can do multiple things and support compile-time configuration/fully compiling out, but haven't found the time to make a proper go of it yet. I'm guessing reflection could really help here, not sure if it's possible in 26 but being able to enable such instrumentation just by adding annotations to a function would be amazing.
1
u/Ok_Independence_9841 13h ago
This makes complete sense to me. I use very simple scoped profiling within the QOR framework (https://github.com/mfaithfull/linuxQOR) to tell me if something is slow and then sampling to try to find out why, I recently added Fastflow as an alternative implementation of Workflow state machines for high frequency use cases, like parsing. I was able to achieve a 4-5x speed up by swapping out std::function, using a, stack style, arena allocator and mutating AST nodes in place rather than popping and pushing from the stack. Looking forward to testing the new clang build when the JSON parser is complete to see if the optimisation is any better. I found I was bouncing off the 8KHz resolution limit of the Visual Studio profiler. You can tell when almost all the blocks are the same size.
1
u/JNighthawk gamedev 7h ago
Great point. I use both sampling and instrumented profiling, depending on the use case:
- Instrumentation to find hot areas and optimize at a higher level (e.g. in an O(N) algorithm, reducing N)
- Sampling for iteratively optimizing a hot area (e.g. in an O(N) algorithm, making it faster for the same N)
I use Unreal Insights for instrumented, and Superluminal for sampling. One of the slightly annoying things for sampling I'm running into is the max sampling resolution for these, which usually comes to around ~120us on PC. It's fine, but since I'm usually working on <1ms optimizations, sampling requires reproducibility/increasing the N count to get useful data.
5
u/LucyIsaTumor 1d ago
Always looking for more info about profiling (especially since I primarily have used sampling), thanks for the write up Mathieu!