GNU bug report logs - #59738
c-ts-mode is slow with large buffers.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Thu, 1 Dec 2022 11:51:02 UTC

Severity: normal

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 59738 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 59738 <at> debbugs.gnu.org
Subject: Re: bug#59738: c-ts-mode is slow with large buffers.
Date: Wed, 7 Dec 2022 16:40:15 -0800

> On Dec 7, 2022, at 9:23 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> Cc: 59738 <at> debbugs.gnu.org
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Tue, 6 Dec 2022 20:56:13 -0800
>> 
>> 
>> Alan Mackenzie <acm <at> muc.de> writes:
>> 
>>> Hello, Emacs.
>>> 
>>> In an up to date (2022-11-30) master started as $ emacs --no-desktop:
>>> 
>>> The file .../drivers/gpu/drm/amd/include/asic_reg/dce/dce_12_0_sh_mask.h
>>> in the Linux source tree is 6.8 MB big, consisting of a large number of
>>> #defines and comments, but nothing else.
>>> 
>>> To scroll through it in c-ts-mode takes a little over 26 minutes on my
>>> system.  By comparison, in C Mode it takes 31 seconds.  There would
>>> appear to be a need for some optimisation in c-ts-mode, here.
>>> [...]
>> Ah, the lovely packet-rrc.c file.
> 
> No, this is a different file, dce_12_0_sh_mask.h.  It is a header file
> which only has preprocessor #define lines.  I'm puzzled why this
> presents such a great difficulty for tree-sitter.  Could you take a
> look what happens with that file?
> 
>> We had some discussion of it in
>> bug#59415, basically it contains some syntax that screws tree-sitter up.
>> The block initialization you see makes tree-sitter into erroneously
>> generating a very tall tree: it recognizes all the opening bracket and
>> ignores (almost) all the closing brackets. That causes operations on the
>> tree to be much much slower than it normally is.
> 
> 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.

Yuan





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

Previous Next


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