Subject: Re: bug#78697: `treesit-major-mode-setup` causing substantial pause when finding a file

From: Eli Zaretskii <[email-masked]>
Date: Thu, 05 Jun 2025 12:09:00 +0300

> 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" <[email-masked]>
> 
> - 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.