Subject: bug#59738: c-ts-mode is slow with large buffers.

From: Eli Zaretskii <[email-masked]>
Date: Thu, 08 Dec 2022 22:37:05 +0200

> From: Yuan Fu <[email-masked]>
> Date: Wed, 7 Dec 2022 16:40:15 -0800
> Cc: Alan Mackenzie <[email-masked]>,
>  [email-masked]
> 
> > Right, but with a long series of #define lines there should be no
> > parse tree at all…
> 
> Ok, I think I know why. At the beginning of the file there is this line
> 
> #ifndef _dce_12_0_SH_MASK_HEADER
> 
> So it’s parsed into a preproc_ifdef node, which contains every #define directive in the file as its immediate child. Now you have this node with a tons of immediate children. And querying this node in font-lock is very slow, even with a limited range. I think for the query result to be accurate, tree-sitter has to query the whole node without considering the range, then throw away matches that are not in the range. 
> 
> Anyway, I activated my backup backup plan, which goes down the parse tree to find a sufficiently small node to query. Now scrolling the header file is fast as other files.

Thanks, now c-ts-mode is twice as fast as c-mode with that file.

Great job!