Whenever Emacs feels slow, or you want to check out just how big the impact of something is RAM or CPU wise, then you can use the built-in Emacs profiler. It’s actually very easy and doesn’t require a lot of prerequisite knowledge. This is a very basic introduction on how to get started with it:
The file in the video includes just one “long” line of code which is 5461 characters long. If it were substantially longer (for example, for a minified JSON file), then Emacs could lock up completely. The semi-arbitrary length of the line of this demo file has been handcrafted to show the issue, but not cause a complete lock-up.
If you’re curious why you’d ever need to profile something in Emacs, maybe because you’re not a developer, let me say it like this: Profiling Emacs can help you even if you’re not a (Lisp) programmer. Sometimes, something might just be slow - for example when you try to edit files that includes long lines in Emacs. Then, profiling comes in quite handy. For this particular issue, we also have a guide on handling long lines in Emacs.
Update (2020-10-10): In post, one piece of information got lost due to an unfortunate cut. After
M-x profiler-start RET, Emacs asks which mode to start the profiler in. The options are
mem. In the demo, I chose
cpu, because I already knew that the issue was CPU bound (previously, I saw 100% load in
top for Emacs whilst the memory footprint was stable).
If you’re into Emacs, chances are that you’re also into Org mode. We’re building a free and open source implementation of Org mode without the dependency of Emacs - built for mobile and desktop browsers: https://github.com/200ok-ch/organice/
If you liked this post and want to say ‘thanks’, please head over to the repository and give it a star. If you’re not into Org mode, we’ve got quite a few other free/libre and open source software products that you might enjoy, instead.