1

Whenever a long string is to be rendered in an emacs buffer, which usually happens in the shell, emacs hangs and freezes, or takes too long to render the text compared to the terminal. What can be done to improve the performance of rendering text in emacs buffers?

  • "Wrong"? "long"? The question is anyway not clear. Please provide a step-by-step recipe to repro the problem, starting with emacs -Q (no init file). Say, at each step, what you see and what you expected to see instead. A true hang is most likely an Emacs bug, in which case you should use M-x report-emacs-bug. – Drew Mar 9 at 20:40
  • FWIW... in Emacs 27, global-so-long-mode addresses a sub-set of these kinds of problem (by turning various slow things off); but it doesn't automatically trigger in the 'dynamic insertion' situations you've mentioned (shell output) and, ultimately, extremely long lines will present problems for the Emacs redisplay code even if no other features are slowing things down (on account of the trade-offs inherent in various other features of the text rendering in Emacs). Nevertheless, so-long.el will likely still be of interest to you. – phils Mar 9 at 22:37
2

As Drew says, your question is a bit vague. However, Emacs does have a long-known problem with long lines in files. Many of the internal operations that Emacs does make the assumption that lines are generally short. This is usually a safe assumption, of course.

As for exactly what is slow, the main problem is usually syntax highlighting. Most syntax highlighting is done with lots of repeated regular expression searches, which generally need to know the line boundaries to work. Turning off font-lock mode for that buffer frequently makes a huge difference.

I doubt the actual text rendering is a big part of the cost; simply rendering glyphs to the screen is generally pretty fast. Deciding which glyphs to render can take more time in some circumstances, but that's mostly related to the script the file is using. Anything that requires shaping will naturally be slower, for example. It still shouldn't be very significant.

If disabling font-lock mode doesn't help enough to satisfy you, I recommend profiling emacs with perf or similar tools. This will let you measure what's actually slow, rather than speculating. Then you may be able to make other adjustments to your configuration that will help.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.