auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Font lock is slow for large doctex document


From: Ikumi Keita
Subject: Font lock is slow for large doctex document
Date: Mon, 12 Jul 2021 16:46:24 +0900

Hi all,

Now font lock operation slows down significantly in a buffer of large
doctex document, at least on machines with somewhat poor CPU power.

[How to confirm]
1. Open "latex/preview.dtx" in AUCTeX distribution, with font lock
   enabled.
2. Type C-v or PageDown repeatedly.
3. As you approach the end of the buffer, the lag from the moment of the
   typing until the window contents is actually scrolled up takes longer
   and longer. In my environment, it eventually takes a few seconds.

[How to fix]
Last year font-latex.el changed its strategy for font lock for in-line
math from syntax-based one to search-based one. Since then, it relies
heavily on texmathp.el.

In LaTeX documents, texmathp.el runs efficiently because it optimizes by
a golden rule "math expressions in LaTeX documents don't contain an
empty line". Of course empty lines frequently appear in LaTeX documents.

However, docTeX documents often lack such true empty lines. The above
example "latex/preview.dtx" is such a document. In such buffer,
`texmathp' must search from (point-min) every time, which slows down the
font lock operation.

My tentative proposal to fix this issue is attached below. With this
patch, `texmathp' regards a line containing only whitespaces except "%"
at its beginning as empty in doctex mode buffer. On my machine, this
eliminates lags described above.

This is equivalent to an assumption "math expressions in docTeX
documents don't contain neither such pseudo-empty lines nor true empty
lines". I'm not sure whether that's right or not, so comments and
suggestion are greatly appreciated.

Best regards,
Ikumi Keita

Attachment: 0001-Fix-slowdown-of-font-lock-in-doctex-mode.patch
Description: adapt texmathp for doctex mode


reply via email to

[Prev in Thread] Current Thread [Next in Thread]