ext/profile, or How to Make Profilers Tell the Truth
When our code runs in slow motion, we reach for profilers. They promise to tell us what’s making it slow.
Or do they? Profilers do not always “tell the truth”. Their non-deterministic nature comes with pitfalls: sampling bias, hidden methods optimized away, misattributed work between threads. Existing profilers rely on a surprising number of tricks to observe Ruby execution internals.
As Ruby evolves with features such as Ractors, M:N threading and JIT, the limits of this external approach are becoming increasingly apparent. The more complex the runtime becomes, the harder it is for profilers outside of the VM.
Let us explore the capabilities and limits of today's Ruby profilers, and show how embedding a profiler, say 'ext/profile', directly into CRuby lets us break fundamental limits of external profiling. What should be called "true"? We will find out by the end.