GNU bug report logs - #78697
`treesit-major-mode-setup` causing substantial pause when finding a file

Previous Next

Package: emacs;

Reported by: alexis purslane <alexispurslane <at> pm.me>

Date: Thu, 5 Jun 2025 01:29:02 UTC

Severity: normal

Full log


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

From: alexis purslane <alexispurslane <at> pm.me>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 78697 <at> debbugs.gnu.org
Subject: Re: bug#78697: `treesit-major-mode-setup` causing substantial pause
 when finding a file
Date: Thu, 05 Jun 2025 13:55:05 +0000
[Message part 1 (text/plain, inline)]
I don't have the original profile anymore, but it was easy enough to reproduce. Here's that reproduced version:

         481  80% - command-execute
         481  80%  - funcall-interactively
         481  80%   - god-mode-self-insert
         262  44%    - funcall-interactively
         261  43%     - project-find-file
         261  43%      - project-find-file-in
         205  34%       - find-file
         205  34%        - find-file-noselect
         202  34%         - find-file-noselect-1
         200  33%          - after-find-file
         195  32%           - normal-mode
         189  31%            - set-auto-mode
         188  31%             - set-auto-mode--apply-alist
         188  31%              - set-auto-mode-0
         188  31%               - clojure-ts-clojurescript-mode
         164  27%                - clojure-ts-mode
         114  19%                 - treesit-major-mode-setup
         114  19%                  - treesit-validate-font-lock-rules
          91  15%                     treesit-query-compile
          23   3%                   clojure-ts--ensure-grammars
          10   1%                 + treesit-ready-p
           1   0%                 + clojure-ts-mode-variables
          24   4%                + run-mode-hooks
           1   0%             + hack-dir-local--get-variables
           6   1%            + font-lock-mode
           5   0%           + run-hooks
           2   0%            insert-file-contents
           1   0%           abbreviate-file-name
           1   0%         + file-truename
           1   0%         + find-buffer-visiting
          52   8%       + project--read-file-name
           4   0%       + project-files
           1   0%     + execute-extended-command
         122  20%    - god-mode-lookup-key-sequence
          85  14%     - god-mode-lookup-command
          85  14%      - apply
          85  14%       - which-key--god-mode-lookup-command-advice
          85  14%        + #<native-comp-function god-mode-lookup-command>
          37   6%     + god-key-string-after-consuming-key
          97  16%    + byte-code
          91  15%   redisplay_internal (C function)
          11   1% + ...
          10   1% + timer-event-handler
           1   0% + which-key--hide-popup

Also, I didn't original report this to the clojurescript-ts-mode folks because (1) since this branched into built-in functions it seemed like an emacs problem, and compoundingly (2) in one of the earlier iterations of my testing I was seeing this performance issue across all files that would load tree-sitter modes; however, I just did another couple tests and profiles with rust, bash, and TSX and didn't see it anymore, so I'll go poke them about it now because it does seem like more of their problem.

On Thursday, June 5th, 2025 at 9:09 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:

> > Date: Thu, 05 Jun 2025 01:27:58 +0000
> > From: alexis purslane via "Bug reports for GNU Emacs,
> > the Swiss army knife of text editors" bug-gnu-emacs <at> gnu.org
> > 

> > - Most time opening a file (38%) is spent within `treesit-major-mode-setup`:
> > 

> > `112,106,431 95% - command-execute ... 84,918,927 72% - find-file 84,916,421 72% - find-file-noselect 84,902,072 72% - find-file-noselect-1 84,852,273 72% - after-find-file 84,735,710 72% - normal-mode 80,077,055 68% - set-auto-mode 79,933,703 68% - set-auto-mode--apply-alist 79,923,463 68% - set-auto-mode-0 79,923,463 68% - clojure-ts-clojurescript-mode 45,382,937 38% - clojure-ts-mode 45,305,561 38% + treesit-major-mode-setup 25,386 0% + treesit-ready-p 20,512 0% + clojure-ts-mode-variables 17,202 0% clojure-ts--ensure-grammars 8,288 0% + clojure-ts--compute-semantic-indentation-rules-cache 34,540,526 29% + run-mode-hooks ...`
> > 

> > The function `clojure-ts-clojurescript-mode` seems to add significant overhead as well, even though it appears to be a simple derived mode that doesn't even have any body forms. It didn't have any problem on Linux.
> 

> 

> Please show the fully expanded profile, with all the levels marked
> with "+" expanded. As posted, the profile stops showing details at
> the most important function: treesit-major-mode-setup, so it is hard
> to come up with ideas what could be the problem.
> 

> Also, since clojure-ts-mode is not part of Emacs, did you report this
> to the mode's developers?
> 

> Thanks.
[publickey - alexispurslane@pm.me - 0x41E61568.asc (application/pgp-keys, attachment)]
[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 10 days ago.

Previous Next


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