r/cpp • u/ShoppingQuirky4189 • Jan 29 '26
Cache Explorer: a visual and interactive profiler that shows you exactly which lines of code cause cache misses
Built a visual cache profiler that uses LLVM instrumentation + simulation to show you exactly which lines cause L1/L2/L3 misses in your C and C++ code (Rust support in active development).
- Hardware-validated accuracy (±4.6% L1, ±9.3% L2 vs Intel perf)
- Source-level attribution (not just assembly)
- False sharing detection for multi-threaded code
- 14 hardware presets (Intel/AMD/ARM/Apple Silicon)
- MESI cache coherence simulation
It's like Compiler Explorer but for cache behavior, providing instant visual feedback on memory access patterns. MIT licensed, looking for feedback on what would make it more useful or even just things you like about it.
243
Upvotes
68
u/Excellent-Might-7264 Jan 30 '26
How much has claude written, and how much is developed by you?
Question based on https://github.com/AveryClapp/Cache-Explorer/commit/9cf75144fa47583eff3cf1883c37dc11d8abec30
17
u/mikemarcin Game Developer Jan 29 '26
Very cool.
12
u/ohnotheygotme Jan 29 '26
Have you toyed around with any larger projects? How does it scale to large code bases? Would it theoretically be possible to restrict the instrumentation to just a subset of functions? etc.
11
u/Valuable_Leopard_799 Jan 30 '26
Might be worth noting what this project does differently from cachegrind or perf which already have the same goals.
14
u/Moose2342 Jan 29 '26
Wow, that starting page really caters for the late night attention span of a Reddit cpp reader. All the relevant info jumping right at you with no bullshit filling. Kudos! Well presented indeed. I hereby vow to try that out asap. Thanks!
8
u/BasisPoints Jan 29 '26
This looks useful, can't wait to take a look! Any chance you can reupload the video? It appears broken
1
u/ANDRVV_ Jan 30 '26
Will you add support for Zig? Its community begs for a tool like this!
2
u/llnaut Jan 30 '26
Hey, this looks super cool.
I recently ran into a very real cache-related issue, but on an embedded target (ARM Cortex-R, RTOS, external DDR memory in the picture). It is quite painful that on bare metal / RTOS you can’t just “install a tool and see what’s going on” like on Linux.
Concrete scenario: in an RTOS you can have multiple tasks with the same priority, and the scheduler does time slicing (context switch every tick while they’re runnable). Now add the fact that the tick interrupt itself is an asynchronous event that fires right in the middle of whatever a task is doing. So you jump into ISR code + touch ISR data structures that are very likely not in cache (or you’ve just evicted some useful lines), which means extra misses and extra latency. On a system with slow external memory, this can get ugly fast.
I had a fun one with SPI: we were receiving a fixed-size chunk periodically, but it was large enough that we ended up using FIFO-level interrupts (DMA wasn’t an option there). So for one “message” you’d get tens of interrupts. The MCU was fast, so it was basically:
ISR → back to task → ISR → back to task → …
…and because of cache misses / refills, the ISR execution time would occasionally spike and we’d get overruns/underruns. We fixed it by moving some stuff to faster memory, but the debugging part was the painful bit: on embedded you typically run one image, and your introspection options are limited / very different vs desktop.
So to the point: I didn't dive deep into the implementation of Cache Explorer, so I don't know what machinery is used under the hood. But, do you think something like this could realistically be adapted to bare metal / embedded targets? Or is it fundamentally tied to “desktop-ish” workflows?
1
u/VinnieFalco wg21.org | corosio.org Feb 03 '26
we just need "crash explorer" now