dgutov / mmm-mode

New official home for mmm-mode, fixed for Emacs >= 23
http://mmm-mode.sourceforge.net/
GNU General Public License v2.0
333 stars 32 forks source link

mmm-mode causes very slow file visiting in large file with relatively slow font-lock #110

Closed stephe-ada-guru closed 4 years ago

stephe-ada-guru commented 4 years ago

I have one file that takes 30 seconds to open.

The problem is that mmm-refontify-maybe calls font-lock-ensure on the entire buffer. As the FIXME: there says, this is a bad idea; font-lock is supposed to work on small portions of the buffer at a time. After fixing this, there is no noticeable delay in opening my large file. Here's a patch:

--- a/mmm-region.el
+++ b/mmm-region.el
@@ -711,10 +711,7 @@ region and mode for the previous position."
   "Re-fontify from START to STOP, or entire buffer, if enabled."
   (when font-lock-mode
     (if (fboundp 'font-lock-flush)
-        (progn
-          (font-lock-flush start stop)
-          ;; FIXME: Do we really need to do this eagerly here?
-          (font-lock-ensure start stop))
+        (font-lock-flush start stop)
       (if (or start stop)
           (font-lock-fontify-region (or start (point-min))
                                     (or stop (point-max)))
stephe-ada-guru commented 4 years ago

I didn't realize github would format the patch. Now attached. slow_startup.diff.txt

dgutov commented 4 years ago

Makes sense, let's try this. Thanks!

purcell commented 4 years ago

I didn't realize github would format the patch.

FWIW, you can surround it with triple-backticks to mark it as a code block, and even tag it with a content type: I did that for you above so you can click "edit" to see how it works.