Profiling Performance in Emacs

Intro

From time to time you will need this, TLDR: all you need to know are 3 commands: M-x profiler-start, M-x profiler-stop, and M-x profiler-report.

Builtin profiler support in Emacs

Emacs has built-in support for this. To begin profiling, type M-x profiler-start . You can choose to profile by processor usage, memory usage, or both. After doing some work, type M-x profiler-report to display a summary buffer for each resource that you chose to profile. The names of the report buffers include the times at which the reports were generated, so you can generate another report later on without erasing previous results. When you have finished profiling, type M-x profiler-stop (there is a small overhead associated with profiling).

Conclusion

Whenever Emacs feels sluggish, don’t panic. Just start the profiler, perform the actions you thought were slow, and check what was causing the trouble under the hood.