zk-phi/indent-guide

huge performance hit on files > 500kB

Closed this issue · 9 comments

I have indent-guides enabled globally and I really love it. However: as soon as files get larger (in my case > 500 kB, but sometimes even at files around 100kB), indent guides makes emacs unusably slow and starts hogging the CPU. I came to this conclusion by using M-x profiler-start and M-x profiler-report. This showed that almost 90% of the cpu usage came from indent-guide-post-command-hook. Is this fixable? The files used aren't even sourcecode files, but simple log files.

indent-guide can be very slow when you open a huge file with most lines indented. You should set indent-guide-inhibit-modes option properly to avoid turning indent-mode on for such files.

A possible solution (not workaround) for slow scan/rendering is caching, but I'm not planning to implement it for now, since indent-guide seems not very useful for such files and we may just disable it (Anyway contributions are welcome!).
Another option is to delay rendering lines until emacs gets idle, but I didn't like it since lines blink everytime I invoke some commands which is distracting.

I would like to contribute, but I have no understanding of (E)Lisp I'm afraid. I will look into it as I find Emacs and indent-guide both very useful :)

I this this should be done as an smart detection before indent-guide apply on buffer.
Let user custom is not a good option.
What do you think? @zk-phi

Examining major-mode before applying indent-guide is also a kind of a smart detection I think.
Building a very perfect algorithm that defines whether a buffer is suitable for indent-guide or not, is probably impossible, so we should make it customizable.
Fixing performance issues is much easier (but still is not very easy) and effective than considering such an algorithm I think.

But what if I want to enable indent-guide in ruby-mode, but some ruby code files are big?
This situation need algorithm.
Like org-mode source code files, I enable indent-guide in emacs-lisp-mode, and when I use [C-h f org-..] to check out the org-mode function definition, the file is big, and Emacs become very slow.
Excluding major-mode does not work in those situations.
We have some things to detect: file size, code indent levels (I don't know about this, how Elisp parse indent start&end, deepest indent level, etc).
With some delay seconds to let indent-guide parse buffer is fine. I think user don't need to see indent lines immediately.
This is what I think.

Did a huge ruby (or emacs-lisp) code really slow down indent-guide so much? (I can't reproduce on my machine) I think that file-size actually has nothing to do with the problem. If it really slows down indent-guide so much, that should be another issue.

MartenBE said:

The files used aren't even sourcecode files, but simple log files.

I suppose most lines in the "log file" are indented. That way, indent-guide can be super slow searching for beginning/end of the block, because they can be so far away. That's not the case for source codes I hope, unless it has a huge function or a block (say, >3000 lines). Thus enabling indent-guide only in source code files seems smart enough for me.

Hmm, right. I see.

Actually those log files weren't indented at all, which is why it took so long for me to figure it out. It was only when I profiled emacs, that I knew indent-guide-post-command-hook was the culprit. But indeed, also small heavily indented xsd files (200 lines max) seem to grind emacs to a halt.

I've just pushed a commit that may improve performance.
If it still make emacs unusably slow, please reopen this issue.