Search code examples
performanceprofilingd

Do all profilers significantly slow execution?


The profilers I have experience with (mainly the Digital Mars D profiler that comes w/ the compiler) seem to massively slow down the execution of the program being profiled. This has a major effect on my willingness to use a profiler, as it makes profiling a "real" run of a lot of my programs, as opposed to testing on a very small input, impractical. I don't know much about how profilers are implemented. Is a major (>2x) slowdown when profiling pretty much a fact of life, or are there profilers that avoid it? If it can be avoided, are there any fast profilers available for D, preferrably for D2 and preferrably for free?


Solution

  • I don't know about D profilers, but in general there are two different ways a profiler can collect profiling information.

    The first is by instrumentation, by injecting logging calls all over the place. This slows down the application more or less. Typically more.

    The second is sampling. Then the profiler breaks the application at regular intervals and inspects the call stack. This does not slow down the application very much at all.

    The downside of a sampling profiler is that the result is not as detailed as with an instrumenting profiler.

    Check the documentation for your profiler if you can run with sampling instead of instrumentation. Otherwise you have some new Google terms in "sampling" and "instrumenting".