felixge / fgprof

🚀 fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together.
MIT License
2.88k stars 96 forks source link

Significantly reduce profiling overhead #6

Closed felixge closed 4 years ago

felixge commented 4 years ago

Avoid calling runtime.GoroutineProfile() twice for every profiling sample by reusing a dynamically growing slice.

On my machine this reduces the average time the world is stopped from 50 µsec to 25 µsec per sample. But whether or not this translates into 2x overhead reduction in the realword will require further testing.

Additionally this patch uses a 100x more efficient approach for counting the stacks. The old approach was taking 8 µsec per aggregation, the new one takes about 90 ns.