unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vincenzo Pupillo <v.pupillo@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>, Yuan Fu <casouri@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: treesitter local parser: huge slowdown and memory usage in a long file
Date: Tue, 13 Feb 2024 10:39:10 +0100	[thread overview]
Message-ID: <3442019.5fSG56mABF@3-191.divsi.unimi.it> (raw)
In-Reply-To: <2F0B4B85-5EAB-4285-BB6B-6CAF24EB96C3@gmail.com>

I don't know if this is a stupid idea or not, but I'll try to explain it. 
My other php-ts-mode (the one without a tree-sitter parser for php) does these things:
there is a "treesit-font-lock-rules" to capture a comment node,
this rule calls a function that tries to figure out if it is a comment block in PHP. If it is a comment block, it uses 
some regular expression for the font-locking, otherwise use treesit-fontify-with-override for the entire comment.
Treesit "knows" the intervals in the file to inject the embedded parser.
Can this information be used for local embedded parsers?

V.

In data martedì 13 febbraio 2024 09:15:49 CET, Yuan Fu ha scritto:
> 
> > On Feb 12, 2024, at 6:09 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> > 
> >> From: Yuan Fu <casouri@gmail.com>
> >> Date: Sun, 11 Feb 2024 20:16:11 -0800
> >> Cc: "Ergus via Emacs development discussions." <emacs-devel@gnu.org>,
> >> Eli Zaretskii <eliz@gnu.org>
> >> 
> >> Thanks, the culprit is the call to treesit-update-ranges in treesit--pre-redisplay, where we don’t pass it any specific range, so it updates the range for the whole buffer. Eli, is there any way to get a rough estimate the range that redisplay is refreshing? Do you think something like this would work?
> >> 
> >>    (treesit-update-ranges
> >>     (max (point-min) (- (window-start) 1000)) ; BEG
> >>     (min (point-max) (+ (or (window-end) (+ (window-start) 4000)) 1000))) ; END
> >> 
> >> I guess the window-start would be outdated in pre-redisplay-function...
> > 
> > The problem is that window-start is not guaranteed to be up-to-date
> > when pre-redisplay-function is called: the window-start is updated by
> > redisplay, and pre-redisplay-function is called before the update.
> > Moreover, pre-redisplay-function could be called either once or twice
> > in a redisplay cycle, and window-start is up-to-date only for the
> > second call.
> > 
> > The window-end point is basically never up-to-date during redisplay,
> > only at its very end.
> > 
> > So my suggestion would be to define the range from position of point,
> > using the window dimensions; see get_narrowed_width for ideas.  This
> > could lose if the buffer has a lot of invisible text, so I suggest to
> > check for invisible properties, and if they are present in the buffer,
> > punt and use the whole accessible portion of the buffer (I don't
> > expect PHP buffers, or any buffers in programming-language modes, to
> > have invisible text).
> 
> Ah, clever :-) Programming language buffers could have invisible text when the user uses hideshow, or folded some section of code using outline-minor-mode :-(
> 
> But as I said in the reply to Dmitry, we might need some better design for updating parser ranges than the current one. I’ll just fix V’s problem for now by updating the range around point, and ignore invisible text for now.
> 
> Yuan
> 







  reply	other threads:[~2024-02-13  9:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-11 21:53 treesitter local parser: huge slowdown and memory usage in a long file 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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2024-04-20  2:18 Yuan Fu
2024-04-20 19:14 ` Vincenzo Pupillo
2024-04-23  5:09   ` Yuan Fu
2024-05-06  2:04 ` Dmitry Gutov
2024-05-09  0:16   ` Yuan Fu
2024-05-12 23:44     ` Dmitry Gutov

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=3442019.5fSG56mABF@3-191.divsi.unimi.it \
    --to=v.pupillo@gmail.com \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).