-
Notifications
You must be signed in to change notification settings - Fork 391
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
about slow syntax highlighting #2877
Comments
To test the slow
I don't understand why finding the closing
by
in |
Thanks for looking into this and for providing some profiling numbers!
Could you check the original pattern without the group, i.e. syntax match texLigature "``\|''\|,," I would think it should be faster still, but it would be nice to see how it compares to your current numbers. (I've pushed an update that does this already, because I can't see how it would not be an improvement. But I'm curious if your suggested version may be even faster.)
Not surprising. It's quite complicated; perhaps needlessly so. I have to admit that it does look equivalent to
Did you already check if the original pattern matches faster than the simplified pattern? That's would be surprising to me.
I've pushed a simplification of the pattern now, and it seems to work well on
I've tested this a little bit further, and I believe that the complexity is not really needed here.
I've simplified this even further. How do the timing look now? |
A quick test seems to indicate that |
Some data for this: I created some files with a couple of lines like 999 times
So it seems like the change you already pushed is better than the way it was. However the pattern |
Here's another idea that might improve syntax highlighting performance. Currently there's a lot of syntax definitions that match specific commands. It might be faster to just have a syntax group that matches commands, i.e. |
Interesting. I can't understand why it would be faster, but I'll switch based on your evidence.
Ok, so the current version is very fast now. That's good. But …
Yes, you are right. I'm sorry for first insisting otherwise. I think using the "trivial"
Yes, you may be right. But it does seem lik a large amount of work to do this. And in my experience, syntax performance is not really a big issue? |
I'll close this, but feel free to continue the discussion. |
From your original list of slow patterns, it seems we should consider the |
Also: If you care to share a nice example file with which you are now testing the syntax speed, that would be nice. I'm thinking of adding an example to the test files so that I have a nice way to reproduce timings. |
I've added a very tiny example here: 2477b87#diff-b6fcc94b4e1e1c06afd70f6fa03d63100d069eed363f356fe23eb30bbe2af033 |
So, the idea here is to scroll through a file, right? So it's
The Thus, it is not so strange that there are big differences in which rules take long. Further, the main things we want is for a single screen render to be quick. For this, we want to have low average (and slowest) times for all rules. We don't want slow rules, or at least we want them to be very rare. |
I found some time to spend on this today. I ended up using the source of this paper https://arxiv.org/abs/1512.07213 to time things with that scrolling script (the non-printable character is Most of it is just "merging" regular expressions, although I also tried changing the Looking at the code probably makes things more clear than I can explain here. |
Interesting. With your branch I do get a very noticeable speedup on my example: Now, I notice you do a lot of different stuff, e.g. changing to the old regex engine. It's a little bit hard to read which of your changes are the most significant. But I'm beginning to think that one of the most significant factors is the number of rules. Thus, as you say, reducing the number of rules by using more complex regexes seems to be a useful trick. |
Now, it looks like you've done a very good and thorough job here. I believe it may be a good idea to add a comment to the top of the core.vim file that summarizes some of the key reflections here? Also, I am wondering if you are proposing that I merge this or if you want to open a PR with your work more cleaned up? |
They are just the runtimes of |
Ok, thanks for clarifying. How about my other questions? |
Hi, I would like to clean this up a bit before opening a PR, and I can write a comment at the top of the file explaining what the main tricks are. |
Sorry, my fault. I must have read the commit log in the wrong order or something.
It's also confusing to me that changing to the old regex engine should have such an impact. The docs themselves say that the old regex engine is slower. I also tested this on a few slow rules when looking into lags related to the fontawesome5 package, and there I did find that the old engine was slower.
That does sound great! I will be very glad to see a PR for this! |
I'm closing this again, since there is now a PR: #3006. |
Description
vimtex's syntax highlighting is a bit slow at times. It's not terrible but if I open a large tex file and scroll up and down with my touchpad it is noticably not smooth. I've tried to look at the output of
:syntime report
and see if there's anything that can be improved. Here's the outputFirst of all, I think the very slow
\v%(``|''|,,)
can be replaced by the equivalent\([`',]\)\1
, which was slightly faster for me, averaging 4us instead of 7us.I was very confused by
\%(\\\@<!\)\@<=\~
. Am I correct in understanding that\\\@<!\~
~
, it will only try to check if there's a backslash before the~
once, instead of trying to match every substring ending before~
against the regex\\
?If so then the same behavior could be achieved with
\\\@1<!\~
which looks simpler. Unfortunately it doesn't seem to give a speedup.Another point is that this regex will parse something like
a\\~b
wrongly. This is more relevant for parsing something like\\\(a^2\)
-- this is valid latex but vimtex's highlighting currently doesn't recognize the math mode (OTOH I don't know why anyone would ever write that). The regex\%(\\\@!\%(\\\\\)*)\@<=\\(
would fix this, checking if there's an even number of backslashes before the\(
. Same goes for detecting~
. The performance of this seems to be slightly worse than\%(\\\@!)\@<=\\(
though. I got 11us vs 9us.Do you use a latexmkrc file?
No
VimtexInfo
The text was updated successfully, but these errors were encountered: