GNU bug report logs - #56682
Fix the long lines font locking related slowdowns

Previous Next

Package: emacs;

Reported by: Gregory Heytings <gregory <at> heytings.org>

Date: Thu, 21 Jul 2022 18:01:01 UTC

Severity: normal

Done: Gregory Heytings <gregory <at> heytings.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ihor Radchenko <yantar92 <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 56682 <at> debbugs.gnu.org, Gregory Heytings <gregory <at> heytings.org>, Eli Zaretskii <eliz <at> gnu.org>, Dmitry Gutov <dgutov <at> yandex.ru>
Subject: bug#56682: Fix the long lines font locking related slowdowns
Date: Mon, 15 Aug 2022 11:10:12 +0800
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>>>> This is needed by Org parser to determine the syntax element at point.
>>> But font-lock widens before using Org-mode's `font-lock-keywords`, so
>>> there should be no need for Org-mode to widen in that case.
>> Yes, but Org parser is not written explicitly for font-locking purposes.
>> org-element-at-point knows nothing about buffer restriction upon
>> calling and thus has to widen to ensure correctness.
>
> That will break uses of MMM-mode where one of the chunks is using
> Org-mode.  Admittedly, this is unlikely, but still: It would be much
> better to arrange to do `widen` *outside* of Org-mode's font-lock (and
> indentation) code.

The fact that MMM-mode is relying on narrowing is a bug in MMM-mode.
Polymode (an alternative to MMM-mode) is using a different approach.

Correct me if I am wrong, but I assume that having a specific major mode
in buffer implies that the whole buffer is considered to contribute to
the major mode.

If the Org parser does not ensure that buffer is widened then the parser
output may depend on the narrowing state. For font-lock, it also means
that different fontification must be used with/without narrowing -
something that font-lock will fail to achieve unless buffer is
re-fontified every time the narrowing changes.

Further, Org parser is caching parse results and reuse them to not
re-parse on every invocation. The need to maintain separate parser
caches for every possible narrowing state will be a nightmare.
Especially considering the user narrowing may also be an option and
having a different parser/command behaviour will be unexpected to the
user.

More generally, prohibiting the innocent-looking
(save-restriction (widen) ...) means that font-lock-keywords cannot
safely call any kind of general-purpose API function without checking
(widen) usage inside that function and inside all the deeper nesting
levels. This will be fragile, especially for user-defined keywords.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92




This bug report was last modified 2 years and 8 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.