-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(treesitter): rely more on ts correctness #18109
base: master
Are you sure you want to change the base?
Conversation
9535cec
to
bce8bcf
Compare
Why remove the state between lines? That seems like a pure regression from a performance perspective (also it just is wrong, we redraw a line range, not a line at a time). |
Because, as most of my fellow developer, I don't have a terrifically deep understanding of the drawing loop. Why not sending the end line in the callback to the redrawing ? |
And what about using static extmarks instead of a complex highlight state ? That will make a huge part of the code simpler to understand. |
Any perf related change must be based on "understanding", other wise it is just a random hit or miss. Profiling can help to get empirical understanding (I have used this to get rid of bottlenecks in unexpected places, such as
That's on_win, and could be alternative, but then the hlstate array might get much longer (at the point we could be starting to see |
Running the test showed a slight improvement in performances. If you don't want the changes, just close that PR, I don't care, I just wanted to raise a point (I did twice) about static extmarks, and you plain ignored it twice. |
simply because I needed to think a bit more about that? you posted it 37 minutes ago, and I don't see the hurry, sorry. it could be simpler, though I like the current code that it doesn't duplicate state already in the tree in a second static copy, so I think that is a point for simplicity as well. |
That is a valid point. Although I think that this is an instance where this simplicity might lead to a bit too much work on the drawing side. I think we'd need real data in order to compare this in real life. I remember I did a similar change a while back, and that lead to significant performance improvements. |
Sure but OTOH if you pre-render whenever the tree is changed, you do more work upfront instead (which might not end up being used). I suspect the trade-off varies greatly how much text-editing vs scrolling around the user does. |
Good point, maybe we need something that redraws the static extmarks in |
d29e373
to
0edc5f9
Compare
@bfredl coming back at this, I am able, with this version of the implementation to limit how far we go on the number of columns. An even better way of doing this (that I don't know though), would be to pass the very specific byte offsets to the |
Thus this version should also fix #14852 |
Any update on this PR ? I think it is already a step forward in fixing bugs... |
06a0a01
to
2fecc69
Compare
I have added the doubling of the match limit value, which should give more room for queries to run. |
For the record, this fixes: |
Now that we have untangled the correctness from perf aspect, perhaps we could break out the former to a separate PR? I e more or less the changes to treesitter.c (including the free list, as that is more or less obvious) |
That is a good idea, if only because the fix should definitely be backported to 0.7. |
I am in favor of this, what parts do you want to separate:
This way we have the fix on one hand a'd the feature on the other? |
I'd say put the kväck and the doubling in a separate |
55a3706
to
2be824d
Compare
For reference, the testcase from lewis6991/gitsigns.nvim#575 is pretty simple:
|
Reproducible, I am going to attempt a little benchmark somehow. |
I am somehow not able to reproduce this using |
Try making the fold as large as possible. |
I finally got a benchmark, as follows: VIMRUNTIME=$(pwd)/runtime/ time nvim --clean -u init.lua ./src/nvim/eval.c -- init.lua
local parser = vim.treesitter.get_parser(0, "c", {})
local highlighter = vim.treesitter.highlighter.new(parser)
local function keys(keys)
vim.api.nvim_feedkeys(keys, 't', true)
end
vim.opt.foldmethod = "manual"
vim.opt.lazyredraw = false
vim.cmd [[1000,7000fold]]
vim.cmd [[999]]
local function mk_keys(n)
local acc = ""
for i = 1, n do
acc = acc .. "j"
end
for i = 1, n do
acc = acc .. "k"
end
return "qq" .. acc .. "q"
end
keys(mk_keys(10))
for i = 1, 100 do
keys "@q"
vim.cmd[[redraw!]]
end
vim.cmd [[quit!]] With this PR : That's a 3x improvement in performance. |
I suppose the presence of a (large) fold could be detected by comparing difference of |
What's a "large enough" fold ? I think that the data above is a clear indicator of a perf improvement. |
idk, as a simple starting point we can just do it for any fold (so whenever delta > 1) |
We really need a dedicated benchmark test suite ( A PR or dedicated issue for discussing this welcome! |
Ding #18989 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
add benchmark from neovim#18109
add benchmark from neovim#18109
Fixes #18108
@bfredl, this removes an old part of the code that was added a long
time ago.
Now comes the question of actually using ephemeral extmarks, and
rather use persistent extmarks and rely on tree updates.
I just leave that there...