Self-Awareness in C++ Code
summary
Built a production memory profiler that instruments allocations inside the Bloomberg Terminal by intercepting heap calls via IAT patching, calling kernel heap APIs and using CaptureStackBackTrace to produce unique call‑stack hashes, per‑pointer maps and a tree histogram UI. Uses thread_local guards to avoid reentrancy, tags allocations with pool/context info and stacks counting allocators (PMR style) to separate pool‑held vs in‑use memory. Finds concrete bugs (example: a logger pool holding huge strings that turns a 500 MB component into 800 MB), runs inside the app with low overhead and produces actionable hotspots.
AI-written summary · about
chapters (32)
- 0:00Intro
- 3:45Tech At Bloomberg
- 5:36The Bloomberg Terminal
- 7:48We care about performance
- 9:21Memory Leaks? In 2018??
- 10:33Memory Usage: A Case Study
- 11:51Usual Strategies
- 13:33Building a memory profiler
- 14:20Where is malloc?
- 15:02Strategy #1: Intercepting malloc using the allocator shim
- 17:36Strategy #2: Intercepting malloc using Import Address Table redirection
- 21:11Capturing the traceback: helper func
- 21:57Step 3: Build a callstack / size histogram
- 22:52Data structures
- 24:36Gotcha #1: recursive malloc
- 24:56Gotcha #1 fix: recursion protection
- 25:12RAll recursion protection
- 25:48Gotcha #2 fix: Thread-local storage
- 26:12Instrumentation walkthrough: 2
- 27:10Instrumentation walkthrough: example
- 27:37Tree representation
- 27:57Building the tree
- 28:12Hierarchical analysis
- 29:03Graphical analysis
- 29:42Example 2: Simple leak
- 30:28Remember our Case Study
- 30:55Case Study: normal run (no errors)
- 31:09Case Study: with some errors
- 31:43Case Study: The logging?
- 34:46Combining callstacks and instance data
- 35:19Allocation context
- 38:44Mixed-mode systems
related talks
27m“From security to performance to GPU programming..."
39mMemory Efficient Java
51mUnderstanding Allocator Impact on Runtime Performance in C++
04m“Profiling Rust Memory Usage with jemalloc”
53mPlugging Memory Leaks With The Chrome Dev Tools
21mMemory Efficient Java
58mC++ Performance and Optimisation
58mLocal (Arena) Memory Allocators Part 1
