all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Yuan Fu <casouri@gmail.com>
Cc: "Ergus via Emacs development discussions." <emacs-devel@gnu.org>
Subject: Re: treesitter local parser: huge slowdown and memory usage in a long file
Date: Mon, 6 May 2024 05:04:41 +0300	[thread overview]
Message-ID: <dc94733b-df75-446c-980e-1c8ea65826cf@gutov.dev> (raw)
In-Reply-To: <2DB11528-C657-4AC1-A143-A13B1EAC897A@gmail.com>

Hi Yuan,

Sorry if I'm being too pedantic here.

On 20/04/2024 05:18, Yuan Fu wrote:

> I believe I’ve found a good way to solve this problem. I pushed the changes to master.
> 
> Basically I added a function treesit-parser-changed-ranges that can directly return the change ranges from last reparse. This means we don’t need to use notifiers to get those change ranges anymore. Then in treesit-pre-redisplay, we reparse the primary parser and get the changed ranges from it.
> 
> Once we have the changed ranges, we update other non-primary parser’s ranges, but only within the changed ranges. Originally we were updating those parser’s ranges on the whole buffer, which led to the slowdown. Then we had to use some workaround to solve this. Now the workaround isn’t needed anymore.

The essence of the change (querying fewer ranges) looks good.

I'm a bit uneasy about the new function and how it's supposed to be 
used. treesit-parser-changed-ranges returns the ranges changes during 
the last reparse. That seems to imply that all of its callers must have 
the up-to-date information about the state of the buffer before that 
reparse, and thus basically follow the parser's updates through some 
mechanism. The implementation also saves some information during every 
reparse, whether somebody is going to call treesit-parser-changed-ranges 
or not.

To take our new code as an example, the only client of 
treesit-parser-changed-ranges now is treesit--pre-redisplay, which is 
called from syntax-propertize-extend-region-functions and 
pre-redisplay-functions.

Is it possible that there would occur multiple changes and reparses 
between some firings of the above hooks? For example, some new feature 
might go over the buffer's text with an automated multi-step 
transformation, calling the parser (but not syntax-ppss) on each step.
In such a scenario it seems treesit--pre-redisplay might miss 
intermediate range updates. Would that be okay?



  parent reply	other threads:[~2024-05-06  2:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20  2:18 treesitter local parser: huge slowdown and memory usage in a long file Yuan Fu
2024-04-20 19:14 ` Vincenzo Pupillo
2024-04-23  5:09   ` Yuan Fu
2024-05-06  2:04 ` Dmitry Gutov [this message]
2024-05-09  0:16   ` Yuan Fu
2024-05-12 23:44     ` Dmitry Gutov
2024-05-22  5:51       ` Yuan Fu
2024-05-22 23:42         ` Dmitry Gutov
  -- strict thread matches above, loose matches on Subject: below --
2024-02-11 21:53 Vincenzo Pupillo
2024-02-12  4:16 ` Yuan Fu
2024-02-12 14:09   ` Eli Zaretskii
2024-02-13  8:15     ` Yuan Fu
2024-02-13  9:39       ` Vincenzo Pupillo
2024-02-13 12:59       ` Eli Zaretskii
2024-02-13  0:50   ` Dmitry Gutov
2024-02-13  8:08     ` Yuan Fu
2024-02-18  3:37       ` Dmitry Gutov
2024-02-19  5:53         ` Yuan Fu
2024-03-21  6:39           ` Yuan Fu

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=dc94733b-df75-446c-980e-1c8ea65826cf@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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.