Treesitter polling instead of parsing on each snippet trigger #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
While attending lectures(only math) and taking notes in markdown everything starts OK.
Side note: I always start with an empty markdown file.
Neovim does not feel slow, everything expands in time and general experience is
good.
Then, closer to the middle of a lecture(~100 lines of markdown written) some snippets won't expand( and expanding takes a good amount of time, at some point it becomes unbearable.
Strangely, executing
:e
helps but not for long, soon enough problem repeatsand at some point, if the lecture is long enough, neovim is slow even after that
procedure.
I am sure that this is mostly due to snippets because without them neovim is
responsive when editing bigger markdown files. My skills in profiling lack so
It was decided to first write a polling mechanism before benchmarking.
Benchmarking
Two benchmarks were done for each case: with and without polling
To benchmark I used luajit's profiler
(which tbh doesn't say much in the end), a minimal neovim configuration and two tests:
down letter c, which will start expanding to many
\subset
'sa piece of markdown in the same file as above
Prerequisites
Minimal configuration used:
init.lua
Here is the file which was edited(~1000 lines):
test.md
Please note that in the given
dotool-###.sh
files there are options that setthe keyboard layout. To execute them correctly you must set yours otherwise it
will produce gibberish(and it is actually dangerous because you don't know what
will it type) or remove them entirely if you use qwerty.
See dotool documentation
Holding the C
It shows how fast luasnip reacts with either polling or no polling.
To measure that, count how many letters
c
did not expand vs how many thereare
\subset
's at the very bottom of a resulting file(the one provided in archive at letterC/*.md.dotool-c.sh
test-polling.md
is result after runningdotool-c.sh
with polling enabling,and
profiler-polling.md
is profiler stats for that runtest-no-polling.md
is result after runningdotool-c.sh
with pollingdisabled, and
profiler-no-polling.md
is profiler stats for that runAs you can see with polling it did much better in terms how many
cc
's wereexpanded.
Typing in a snippet
There is a file which types a snippet(works only on Linux, obviously read before
execution):
dotool-snip.sh
Typing robotically a snippet of markdown with latex is assumed to show something
in profiler results,... doesn't tell much though. Both mechanisms did well
On PR
Inspired by #11
Libuv's timer has a delay of 100, which might be a bit too frequent. I believe
setting it to 200 or even 300 wouldn't hurt although I didn't try.
There was no field-testing as i have a pause in studies, so I actually don't
know how it behaves when editing markdown for a prolonged time.
Also if it behaves well, I would drop support of non-cached
is_math
andnot_math
.Q: why use polling instead of triggering updates on every keypress?
A:
(from https://neovim.io/doc/user/treesitter.html#lua-treesitter-languagetree)
This is a draft, and I am open to any suggestions.
Archive with the results:
ls-latex-snips-benchmark.zip