-
Notifications
You must be signed in to change notification settings - Fork 121
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
Feature request: Improve speed #14
Comments
Thanks for raising the issue. I'll see what I can do. |
To give you an example to work with: 32 & 1.14\e 1& & 5.65\e 2& & & & 1.16\e 1& & 1.28\e 1& \\
64 & 1.03\e 1& 0.1 & 4.98\e 2& 0.2 & & & 9.21\e 2& 0.3 & 1.02\e 1& 0.3\\
128 & 9.86\e 2& 0.1 & 4.69\e 2& 0.1 & & & 8.46\e 2& 0.1 & 9.45\e 2& 0.1\\
256 & 9.65\e 2& 0.0 & 4.59\e 2& 0.0 & & & 8.15\e 2& 0.1 & 9.11\e 2& 0.1\\
512 & 9.55\e 2& 0.0 & 4.56\e 2& 0.0 & & & 8.01\e 2& 0.0 & 8.96\e 2& 0.0\\
1024 & 9.49\e 2& 0.0 & 4.53\e 2& 0.0 & & & 7.94\e 2& 0.0 & 8.89\e 2& 0.0\\
2048 & 9.47\e 2& 0.0 & 4.52\e 2& 0.0 & & & 7.91\e 2& 0.0 & 8.85\e 2& 0.0\\
4096 & 9.46\e 2& 0.0 & 4.51\e 2& 0.0 & & & 7.90\e 2& 0.0 & 8.83\e 2& 0.0\\
8192 & 9.45\e 2& 0.0 & 4.51\e 2& 0.0 & & & & & & \\ To align this table with |
Whoa, 10 seconds for just 9 lines? That is not normal. |
Ah, I see. I can confirm that if I use EasyAlign with no filetype, then it is fast here as well. The problem has to do with the combination of EasyAlign file type plugins for LaTeX (and perhaps other file types). I will investigate when I have the chance and try to find exactly what in the file type plugin that creates the lag. |
Hmm, can you try again with Finding out syntax highlighting group of a certain position is known to be a relatively slow operation. ( |
I tried that, but it did not seem to have any effect. However, I also tried to turn off folding, and then it seems to work as expected. I also tried a very coarse fix to let oldfen = &fen
let &fen = 0
try
call s:align(a:bang, a:firstline, a:lastline, a:expr)
catch 'exit'
endtry
let &fen = oldfen This also seems to fix my issue completely. I think this is the correct way to disable folding temporarily, but I am not sure if this is the correct place to add it in your code. |
Nice find! I never suspected folding since I myself don't usually use it. |
And could you check if |
I've tested with the following fix that temporarily overrides foldmethod to manual during alignment, function! easy_align#align(bang, expr) range
let st = reltime()
let ofm = &l:foldmethod
try
let &l:foldmethod = 'manual'
call s:align(a:bang, a:firstline, a:lastline, a:expr)
catch 'exit'
finally
let &l:foldmethod = ofm
endtry
redraw
echom reltimestr(reltime(st))
endfunction It works great for small LaTeX files, however for very large files it can hurt performance. The problem is, reverting &foldmethod to what it was before (e.g.
Files with several thousand lines are rare, but 200-line tables are also extremely uncommon. So I'm not sure at this point if we should make this fix the default behavior of EasyAlign. |
This is strange. The particular example where I noticed the problem is a file with about 1000L with tables of approximately 10L each. I'm happy to say that the latest versions of plugins are faster and now only take about 2 seconds for aligning, not 9. I don't know what has changed, though. Another thing: I am not sure if your way of benchmarking is accurate (using If it is of help, you can look at my tex file. My reported timings come from aligning the 9 last lines from the bottommost table. I think you should also be able to notice the difference between instant (with the fix) and a delay (without the fix). I think the fix should either be default, or at least possible to use through an option. |
After you created this issue, I've optimized some inefficient code, so I guess what you see is the result of it.
Please make sure you don't run EasyAlign command in interactive mode when measuring the response time. The time EasyAlign command waits for keystrokes is included. Instead use non-interactive command:
I think I'm going to make this feature optional with a global variable switch because it doesn't always yield the better result as I've shown you above. (FYI, neither Align.vim nor Tabular addresses this issue.) I'll keep you updated with the progress. |
Nice!
Ah, of course. Silly me. My timings are as follows (no fix/fix):
As you see, I do not experience the lag due to changing the foldmethod that you reported, and with the fix, the timings are comparable for all file sizes.
I understand that you want to keep this change optional as long as you are not fully convinced that it is always optimal. And I am very happy that you want to address this at all :) |
It seems that the cost of setting &foldmethod to expr depends not only on the number of let st = reltime() | let &l:foldmethod='expr' | redraw | echom reltimestr(reltime(st)) The above code takes 0.42 seconds for mostly-empty 8000L LaTeX file, And of course, the fold cost will vary from plugin to plugin. |
I just now noticed that you add |
If we do it without redraw, let st = reltime() | let &l:foldmethod='expr' | echom reltimestr(reltime(st)) it returns faster, echom prints short response time, but I noticed that Vim is unresponsive after the message for some period, and it seemed to me that adding redraw is required to measure the actual delay a user experiences. |
There is one thing I just realized: let st = reltime() | setlocal nofoldenable | setlocal foldenable | redraw | echom reltimestr(reltime(st)) This is almost free compared to setting foldmethod! |
Ah, nevermind. |
Hmm, perhaps you are right. At least I do not experience any difference in responsiveness if I add redraw. I feel like there should be some way of changing lines that does not invoke the folding. I tried a quick search, but unfortunately I don't find anything about this. |
https://github.com/junegunn/vim-easy-align#disabling-foldmethod-during-alignment Updated with |
It seems to work well, thanks! |
Good to hear that. I'll close this issue for the time being. If you happen to find a better approach to tackle this problem, feel free to let me know. Thanks. |
Hi,
I have not looked at the code for
vim-easy-align
, so I am not sure to which extent it is optimized or not. However, when I use the:EasyAlign
command for relatively complex tables that spans multiple lines and columns, I find it is rather slow. If there is any chance of optimizing the code for more speed, that would be great!The text was updated successfully, but these errors were encountered: