GNU bug report logs - #69071
Emacs master branch: c-ts-mode is slow with large C functions.

Previous Next

Package: emacs;

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

Date: Mon, 12 Feb 2024 11:41:02 UTC

Severity: normal

To reply to this bug, email your comments to 69071 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Mon, 12 Feb 2024 11:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 12 Feb 2024 11:41:02 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Emacs master branch: c-ts-mode is slow with large C functions.
Date: Mon, 12 Feb 2024 11:30:00 +0000
Hello, Emacs.

Using Emacs master:

c-ts-mode is slow on large C functions when editing towards the end of
such a function.

As an extreme example, there is a function proto_register_rrc in the
file packet-rrc.c which is part of Wireshark.  This file is "available"
from Github, but sadly no longer freely available - you need to allow
Microsoft's scripts to run on your machine.  I'm willing to send this
file by email to anybody who needs it.  It is almost 10 MB in size.

proto_register_rrc is around 50,000 lines long, total size about 2¼ MB.

Near the end of the function, after typing a character, there is a delay
of between 9 and 10 seconds (on my 7 year old machine) before redisplay
happens.  This is too long.  Some optimisation seems needed.

On disabling font-lock-mode, the response becomes instantaneous.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Mon, 12 Feb 2024 13:26:02 GMT) Full text and rfc822 format available.

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

From: Kévin Le Gouguec <kevin.legouguec <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Mon, 12 Feb 2024 14:14:05 +0100
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, Emacs.
>
> Using Emacs master:
>
> c-ts-mode is slow on large C functions when editing towards the end of
> such a function.
>
> As an extreme example, there is a function proto_register_rrc in the
> file packet-rrc.c which is part of Wireshark.  This file is "available"
> from Github, but sadly no longer freely available - you need to allow
> Microsoft's scripts to run on your machine.  I'm willing to send this
> file by email to anybody who needs it.  It is almost 10 MB in size.

Assuming we are talking about the same 10 MB file:

  $ wget https://raw.githubusercontent.com/wireshark/wireshark/master/epan/dissectors/packet-rrc.c

or

  $ git clone --depth 1 https://github.com/wireshark/wireshark 
  $ find wireshark -name packet-rrc.c

might help?

I'd suggest heeding that repository's disclaimer and using the canonical
GitLab repo instead of the read-only GitHub mirror, but odds are
gitlab.com's JS won't fare better on the freedom front.  Debian's mirror
might?

https://salsa.debian.org/debian/wireshark/-/blob/debian/master/epan/dissectors/packet-rrc.c

> proto_register_rrc is around 50,000 lines long, total size about 2¼ MB.
>
> Near the end of the function, after typing a character, there is a delay
> of between 9 and 10 seconds (on my 7 year old machine) before redisplay
> happens.  This is too long.  Some optimisation seems needed.
>
> On disabling font-lock-mode, the response becomes instantaneous.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Thu, 15 Feb 2024 08:37:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>, Yuan Fu <casouri <at> gmail.com>
Cc: 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Thu, 15 Feb 2024 10:36:11 +0200
> Date: Mon, 12 Feb 2024 11:30:00 +0000
> From: Alan Mackenzie <acm <at> muc.de>
> 
> Using Emacs master:
> 
> c-ts-mode is slow on large C functions when editing towards the end of
> such a function.
> 
> As an extreme example, there is a function proto_register_rrc in the
> file packet-rrc.c which is part of Wireshark.  This file is "available"
> from Github, but sadly no longer freely available - you need to allow
> Microsoft's scripts to run on your machine.  I'm willing to send this
> file by email to anybody who needs it.  It is almost 10 MB in size.
> 
> proto_register_rrc is around 50,000 lines long, total size about 2¼ MB.
> 
> Near the end of the function, after typing a character, there is a delay
> of between 9 and 10 seconds (on my 7 year old machine) before redisplay
> happens.  This is too long.  Some optimisation seems needed.
> 
> On disabling font-lock-mode, the response becomes instantaneous.

Yuan, could you please look into this?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Fri, 16 Feb 2024 04:09:02 GMT) Full text and rfc822 format available.

Message #14 received at 69071 <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>, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Thu, 15 Feb 2024 20:06:44 -0800

> On Feb 15, 2024, at 12:36 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> Date: Mon, 12 Feb 2024 11:30:00 +0000
>> From: Alan Mackenzie <acm <at> muc.de>
>> 
>> Using Emacs master:
>> 
>> c-ts-mode is slow on large C functions when editing towards the end of
>> such a function.
>> 
>> As an extreme example, there is a function proto_register_rrc in the
>> file packet-rrc.c which is part of Wireshark.  This file is "available"
>> from Github, but sadly no longer freely available - you need to allow
>> Microsoft's scripts to run on your machine.  I'm willing to send this
>> file by email to anybody who needs it.  It is almost 10 MB in size.
>> 
>> proto_register_rrc is around 50,000 lines long, total size about 2¼ MB.
>> 
>> Near the end of the function, after typing a character, there is a delay
>> of between 9 and 10 seconds (on my 7 year old machine) before redisplay
>> happens.  This is too long.  Some optimisation seems needed.
>> 
>> On disabling font-lock-mode, the response becomes instantaneous.
> 
> Yuan, could you please look into this?

Oops, didn’t see this. I’ll take a look.

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Tue, 20 Feb 2024 05:52:02 GMT) Full text and rfc822 format available.

Message #17 received at 69071 <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>, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Mon, 19 Feb 2024 21:49:26 -0800

> On Feb 15, 2024, at 8:06 PM, Yuan Fu <casouri <at> gmail.com> wrote:
> 
> 
> 
>> On Feb 15, 2024, at 12:36 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>> 
>>> Date: Mon, 12 Feb 2024 11:30:00 +0000
>>> From: Alan Mackenzie <acm <at> muc.de>
>>> 
>>> Using Emacs master:
>>> 
>>> c-ts-mode is slow on large C functions when editing towards the end of
>>> such a function.
>>> 
>>> As an extreme example, there is a function proto_register_rrc in the
>>> file packet-rrc.c which is part of Wireshark.  This file is "available"
>>> from Github, but sadly no longer freely available - you need to allow
>>> Microsoft's scripts to run on your machine.  I'm willing to send this
>>> file by email to anybody who needs it.  It is almost 10 MB in size.
>>> 
>>> proto_register_rrc is around 50,000 lines long, total size about 2¼ MB.
>>> 
>>> Near the end of the function, after typing a character, there is a delay
>>> of between 9 and 10 seconds (on my 7 year old machine) before redisplay
>>> happens.  This is too long.  Some optimisation seems needed.
>>> 
>>> On disabling font-lock-mode, the response becomes instantaneous.
>> 
>> Yuan, could you please look into this?
> 
> Oops, didn’t see this. I’ll take a look.

Before we continue, let me note that this seems like another case where tree-sitter-c parser chokes on some extreme C code. Profiler reports shows that almost all time are spent in treesit-parser-root-node, which indicates that all the time are spent parsing the text.

Yuan


        6094  61% - ...
        5542  55%  - self-insert-command
        5542  55%   - electric-indent-post-self-insert-function
        5542  55%    - indent-according-to-mode
        5542  55%     - treesit-indent
        5542  55%      - let*
        5542  55%       - treesit--indent-1
        5542  55%        - let*
        5542  55%         - cond
        5542  55%          - treesit-node-at
        5542  55%           - let*
        5542  55%            - if
        5542  55%             - or
        5542  55%              - treesit-buffer-root-node
        5542  55%               - let*
        5542  55%                - if
        5542  55%                   treesit-parser-root-node
         552   5%  + #<compiled 0x1812af33e570332e>
        3834  38% - redisplay_internal (C function)
        3824  38%  - redisplay--pre-redisplay-functions
        3824  38%   - run-hook-with-args
        3824  38%    - treesit--pre-redisplay
        3824  38%     - if
        3824  38%      - let
        3824  38%       - while
        3824  38%        - let
        3824  38%           treesit-parser-root-node
           5   0% + command-execute
           5   0% + timer-event-handler





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Tue, 20 Feb 2024 13:57:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: acm <at> muc.de, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Tue, 20 Feb 2024 15:55:53 +0200
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Mon, 19 Feb 2024 21:49:26 -0800
> Cc: Alan Mackenzie <acm <at> muc.de>,
>  69071 <at> debbugs.gnu.org
> 
> Before we continue, let me note that this seems like another case where tree-sitter-c parser chokes on some extreme C code. Profiler reports shows that almost all time are spent in treesit-parser-root-node, which indicates that all the time are spent parsing the text.

So maybe this is something to report to tree-sitter and/or
tree-sitter-c developers?  (Does c++-ts-mode behave better with this
file?)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Sat, 24 Feb 2024 20:45:02 GMT) Full text and rfc822 format available.

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

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: acm <at> muc.de, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Sat, 24 Feb 2024 12:35:50 -0800

> On Feb 20, 2024, at 5:55 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Mon, 19 Feb 2024 21:49:26 -0800
>> Cc: Alan Mackenzie <acm <at> muc.de>,
>> 69071 <at> debbugs.gnu.org
>> 
>> Before we continue, let me note that this seems like another case where tree-sitter-c parser chokes on some extreme C code. Profiler reports shows that almost all time are spent in treesit-parser-root-node, which indicates that all the time are spent parsing the text.
> 
> So maybe this is something to report to tree-sitter and/or
> tree-sitter-c developers?  (Does c++-ts-mode behave better with this
> file?)

We could, but honestly I don’t think they can/want to do anything.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Sun, 25 Feb 2024 05:56:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: acm <at> muc.de, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Sun, 25 Feb 2024 07:48:00 +0200
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Sat, 24 Feb 2024 12:35:50 -0800
> Cc: acm <at> muc.de,
>  69071 <at> debbugs.gnu.org
> 
> 
> 
> > On Feb 20, 2024, at 5:55 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > 
> >> From: Yuan Fu <casouri <at> gmail.com>
> >> Date: Mon, 19 Feb 2024 21:49:26 -0800
> >> Cc: Alan Mackenzie <acm <at> muc.de>,
> >> 69071 <at> debbugs.gnu.org
> >> 
> >> Before we continue, let me note that this seems like another case where tree-sitter-c parser chokes on some extreme C code. Profiler reports shows that almost all time are spent in treesit-parser-root-node, which indicates that all the time are spent parsing the text.
> > 
> > So maybe this is something to report to tree-sitter and/or
> > tree-sitter-c developers?  (Does c++-ts-mode behave better with this
> > file?)
> 
> We could, but honestly I don’t think they can/want to do anything.

I suggest to report this anyway: we don't have anything to lose, and
there's a chance they would like to do something.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Fri, 01 Mar 2024 01:29:02 GMT) Full text and rfc822 format available.

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

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: acm <at> muc.de, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Thu, 29 Feb 2024 17:26:50 -0800

> On Feb 24, 2024, at 9:48 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Sat, 24 Feb 2024 12:35:50 -0800
>> Cc: acm <at> muc.de,
>> 69071 <at> debbugs.gnu.org
>> 
>> 
>> 
>>> On Feb 20, 2024, at 5:55 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>>> 
>>>> From: Yuan Fu <casouri <at> gmail.com>
>>>> Date: Mon, 19 Feb 2024 21:49:26 -0800
>>>> Cc: Alan Mackenzie <acm <at> muc.de>,
>>>> 69071 <at> debbugs.gnu.org
>>>> 
>>>> Before we continue, let me note that this seems like another case where tree-sitter-c parser chokes on some extreme C code. Profiler reports shows that almost all time are spent in treesit-parser-root-node, which indicates that all the time are spent parsing the text.
>>> 
>>> So maybe this is something to report to tree-sitter and/or
>>> tree-sitter-c developers?  (Does c++-ts-mode behave better with this
>>> file?)
>> 
>> We could, but honestly I don’t think they can/want to do anything.
> 
> I suggest to report this anyway: we don't have anything to lose, and
> there's a chance they would like to do something.
> 
> Thanks.

I created an issue here: https://github.com/tree-sitter/tree-sitter-c/issues/196

Hopefully it captures the issue.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69071; Package emacs. (Fri, 01 Mar 2024 07:11:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: acm <at> muc.de, 69071 <at> debbugs.gnu.org
Subject: Re: bug#69071: Emacs master branch: c-ts-mode is slow with large C
 functions.
Date: Fri, 01 Mar 2024 09:09:40 +0200
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Thu, 29 Feb 2024 17:26:50 -0800
> Cc: acm <at> muc.de,
>  69071 <at> debbugs.gnu.org
> 
> > I suggest to report this anyway: we don't have anything to lose, and
> > there's a chance they would like to do something.
> > 
> > Thanks.
> 
> I created an issue here: https://github.com/tree-sitter/tree-sitter-c/issues/196
> 
> Hopefully it captures the issue.

Thanks, let's hope indeed.




This bug report was last modified 64 days ago.

Previous Next


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