[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter indentation for js-mode & cc-mode
From: |
Yuan Fu |
Subject: |
Re: Tree-sitter indentation for js-mode & cc-mode |
Date: |
Fri, 28 Oct 2022 12:43:31 -0700 |
> On Oct 28, 2022, at 2:10 AM, Theodor Thornhill <theo@thornhill.no> wrote:
>
> Yuan Fu <casouri@gmail.com> writes:
>
>>>
>>>>> looking up way to much the root of the tree, but you know the internals
>>>>> here better than me. Is this something we can optimize away? See the
>>>>> attached report at the bottom.
>>>>
>>>> This is very strange, I need to look into it.
>>>>
>>>
>>> I'm happy to provide more info and profiling, as well as testing if need
>>> be!
>>
>> I just tried running treesit-buffer-root-node and treesit-node-at
>> 10000 times in the end of buffer and they are pretty fast, so I don’t
>> know why the benchmark says 99% time is spent in
>> treesit-buffer-root-node. Could you share the benchmark code and test
>> file? Thanks!
>>
>> Yuan
>
>
> Absolutely. I ran the test again - see test file and new report in
> attachments.
>
> You need to `M-x eval-buffer` in `treesit.el` to avoid the compiled
> functions to get better profile report, then in the testfile:
>
> M-x profiler-start
> C-x h ;; (mark-whole-buffer)
> C-i ;; (indent-for-tab-command)
> ;; --- waaaaait
> M-x profiler-stop
> M-x profiler-report
>
> There's no test code for this, just running the commands sequentially
> and get the report :-)
>
> Are we parsing the whole file over and over in treesit-buffer-root-node?
> Do we for some reason not hit the early return?
>
> The js-file [0] is taken from [1] and duplicated and messed up
> indentation. Report [2] was messed up by dpaste it seems. Gmail didn't
> want the files as attachments, so paste it is :-)
>
> Hope this is useful!
>
> Theo
>
Ok, I’m fairly certain this is due to tree-sitter reparsing after we indenting
each line: treesit-buffer-root-node asks for the root node of the parser, which
triggers a reparse, because last indent modified the buffer. We are basically
reparsing as many time as there are lines in the buffer.
Indenting a similarly sized buffer where all indent are good is much faster,
because there is no reparse due to change to the buffer.
Tree-sitter indent should add an implementation for indent-for-region function
which precomputes indent for each line and indent lines in batch. That ought to
fix it. Added to TODO :-)
Yuan
- Tree-sitter indentation for js-mode & cc-mode, Yuan Fu, 2022/10/26
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/27
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/27
- Re: Tree-sitter indentation for js-mode & cc-mode, Yuan Fu, 2022/10/27
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/27
- Re: Tree-sitter indentation for js-mode & cc-mode, Yuan Fu, 2022/10/28
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/28
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/28
- Re: Tree-sitter indentation for js-mode & cc-mode,
Yuan Fu <=
- Re: Tree-sitter indentation for js-mode & cc-mode, Theodor Thornhill, 2022/10/28
- Re: Tree-sitter indentation for js-mode & cc-mode, Yuan Fu, 2022/10/28
- Re: Tree-sitter indentation for js-mode & cc-mode, Eli Zaretskii, 2022/10/29
- Re: Tree-sitter indentation for js-mode & cc-mode, Yuan Fu, 2022/10/29