all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: JD Smith <jdtsmith@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: dmitry@gutov.dev, 71345@debbugs.gnu.org
Subject: bug#71345: Feature: unleash font-lock's secret weapon; handle Qfontified = non-nil
Date: Tue, 4 Jun 2024 08:08:40 -0400	[thread overview]
Message-ID: <DAC8D262-0862-45ED-BD3A-D95ED5FE9793@gmail.com> (raw)
In-Reply-To: <jwvtti9lcf0.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3464 bytes --]


> 
>> That starts to sound like a lot of property slinging, which might even
>> dominate the work done.
> 
> Indeed, this amount of work could become significant.  It's my main
> worry, but I don't have a clear feel for how serious it would be
> in practice.

In my situation, the most likely scenario is that fontified=nil is noticed during redisplay when there is a fairly large stretch of already-fontified property having the same value.  So jit-lock-fontify-now will quickly find a nice large chunk to call my FONTIFICATION-FUNCTION=F-F with.

Since jit-lock-after-change will likely clear away already-fontified and set fontified=nil, a single additional F-F on top of jit-lock-function will probably be very well handled.  A good question is how it would scale with more functions all operating in the same region.  One idea is to rig up a test file, do some fake jit-lock-flushing on it, and check performance of just subtracting/searching/dividing the already-fontified property as you add more (fake) F-F's.   For me, jit-lock-fontify-now of a 2500 char chunk in a heavy treesitter buffer is in the 2-5ms range.  Individual F-F's could be much lighter weight.

> We could try and unify `fontified` and `jit-lock-already-fontified` by
> having a `fontified-done-value` variable and making the redisplay call
> jit-lock whenever `fontified` has a value that's not-eq from
> `fontified-done-value`.
> 
> So jit-lock would set `fontified-done-value` to the list of backends.

Nice idea.  Since redisplay just directs jit-lock to a "starting position", it would be free to update however much buffer text it wants.  To overcome the issue of "many small domains", jit-lock could cheat, for example checking if ANY chars in the next block need a particular F-F, and running it on the full block if so.  That's already implicitly how jit-lock works now if I understand correctly.  But things like `text-property-any' will be quickly defeated by the combinatorics of a large F-F set.  Also, an advantage of keeping the fontified=nil semantics is that changes to jit-lock could be back-ported to earlier Emacs versions.

So here's an idea.  You could invert the logic, and have a set of `fontified-pending' properties which jit-lock-flush adds to as it sets fontified=nil, maintaining one property symbol for each F-F (e.g. fontified-pending-N).  Then jit-lock-flush's only job is to select and apply one such property over the region, and fontify-now can use a simple and very fast `text-property-any' as it loops through the list of F-F's, and a final `remove-list-of-text-properties' to strip them all away.  For the convenience of jit-lock-after-change, setting a "single property to rule them all" (fontified-pending=t) directs jit-lock to run all the F-F's, there.  fontify-now could check for that first, then only bother to look for the individual (-N) properties if it is not set.  Is there code out there that sets fontified=nil on its own or is that an internal detail of jit-lock?

>> I imagine that the functions may also need a way to opt-out of "deferred
>> contextual refontification", for example if they add some other
>> properties/overlays orthogonal to face.
> 
> `jit-lock.el` already has that info (it's the second arg to
> `jit-lock-register`), but it currently doesn't keep track of it
> individually for each backend.

Great, so this information could be put into action using one of these approaches.


[-- Attachment #2: Type: text/html, Size: 4739 bytes --]

  reply	other threads:[~2024-06-04 12:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-03 16:35 bug#71345: Feature: unleash font-lock's secret weapon; handle Qfontified = non-nil JD Smith
2024-06-03 16:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-03 21:14   ` JD Smith
2024-06-04  1:44     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04 12:08       ` JD Smith [this message]
2024-06-04 14:15         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04 15:38           ` JD Smith
2024-06-04 21:52             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04 22:41               ` JD Smith
2024-06-05 11:29                 ` Eli Zaretskii
2024-06-05 14:02                   ` JD Smith
2024-06-05 14:53                     ` Eli Zaretskii
2024-06-05 15:52                       ` JD Smith
2024-06-05 17:00                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 17:24                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 11:24               ` Eli Zaretskii
2024-06-05 14:05                 ` JD Smith
2024-06-05 16:28                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 16:38                   ` Eli Zaretskii
2024-06-05 16:59                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 17:52                       ` Eli Zaretskii
2024-06-05 18:13                         ` JD Smith
2024-06-07  3:27                         ` JD Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DAC8D262-0862-45ED-BD3A-D95ED5FE9793@gmail.com \
    --to=jdtsmith@gmail.com \
    --cc=71345@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.