vim-easytags
vim-easytags copied to clipboard
Easytags is making Vim's cursor very slow after a few minutes of use
Hi,
After a few minutes of use, my Vim is getting very slow, even when something as simple as moving the cursor.
I profiled the running function and got this result:
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
3 0.006288 0.002934 <SNR>79_AutoUpdate()
3 0.003460 0.001882 xolox#easytags#autoload()
3 0.002858 0.000117 <SNR>79_HighlightTag()
3 0.002741 0.002732 <SNR>79_GetNearbyTag()
15 0.001804 <SNR>44_Highlight_Matching_Pair()
3 0.000657 0.000507 xolox#easytags#get_tagsfile()
21 0.000559 xolox#misc#option#get()
3 0.000361 0.000083 xolox#easytags#file_has_tags()
6 0.000279 0.000088 <SNR>31_resolve()
3 0.000252 0.000223 <SNR>79_IsValidFile()
18 0.000191 <SNR>79_LogDebugMessage()
3 0.000170 xolox#easytags#supported_filetypes()
3 0.000157 <SNR>31_cache_tagged_files()
9 0.000051 112()
3 0.000017 114()
3 0.000014 <SNR>31_create_context()
3 0.000014 111()
3 0.000009 110()
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
3 0.006288 0.002934 <SNR>79_AutoUpdate()
3 0.002741 0.002732 <SNR>79_GetNearbyTag()
3 0.003460 0.001882 xolox#easytags#autoload()
15 0.001804 <SNR>44_Highlight_Matching_Pair()
21 0.000559 xolox#misc#option#get()
3 0.000657 0.000507 xolox#easytags#get_tagsfile()
3 0.000252 0.000223 <SNR>79_IsValidFile()
18 0.000191 <SNR>79_LogDebugMessage()
3 0.000170 xolox#easytags#supported_filetypes()
3 0.000157 <SNR>31_cache_tagged_files()
3 0.002858 0.000117 <SNR>79_HighlightTag()
6 0.000279 0.000088 <SNR>31_resolve()
3 0.000361 0.000083 xolox#easytags#file_has_tags()
9 0.000051 112()
3 0.000017 114()
3 0.000014 <SNR>31_create_context()
So apparently TagBar and EasyTags are causing most of the lag.
Any Python file will make Vim slow, especially big ones. My vim dotfiles are here: https://github.com/charlax/dotvim
Here are some settings that are related to the plugin:
" Disable automatic highlighting
let b:easytags_auto_highlight = 0
I did not change updatetime
.
Thanks for your help!
Same for me
I'm not sure if this is directly related, but I changed g:easytags_dynamic_files
to 2
and deleted ~/.vimtags
. After that I had no more issues with cursor lag.
@charlax: Thanks for reporting the issue, and also for trying to diagnose the issue. However I'm not sure if the profile output is indicative of anything:
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
3 0.006288 0.002934 <SNR>79_AutoUpdate()
3 0.003460 0.001882 xolox#easytags#autoload()
The total time column contains a score of 0.003460 for xolox#easytags#autoload()
, meaning it spent a total of 0.003460 wall clock seconds; unless your profile sample was from a very short duration, I don't see that being a big performance impact... If I'd have to venture a guess as to the real cause of the slow down, it would be this:
@ everyone:
Vim's syntax highlighting engine does not like vim-easytags. Depending on your perspective, vim-easytags is abusing Vim's syntax highlighting engine. So indeed it slows text editing in Vim down. I notice this as well, every day :-). For me the additional syntax highlighting is worth it. To some it might not be worth it.
A small sidebar: After writing most of this reply, I realized I should have read the original issue more carefully; @charlax specifically disabled the dynamic syntax highlighting performed by vim-easytags. However I also see HighlightTag()
near the top of the profile report. This function is not defined by vim-easytags so I suppose it's coming from TagBar, which I'm not familiar with. If that plug-in highlights tags returned by Vim's tagfiles()
, it doesn't really matter whether vim-easytags or TagBar is doing the highlighting; the point is that it is happening :-).
If TagBar does not highlight tags, the only remaining option I can think of is that TagBar does something (useful) with your tags, so its speed is in some sense bound to the number of available tags. Since vim-easytags always makes sure you have the maximum possible number of tags available, TagBar performs bad.
Returning to my original explanation now: Over the years I've tried in several different ways to minimize the number of tags highlighted by vim-easytags, without losing highlighting of anything relevant:
- Local tags (private to one file) which are not defined in the current file are not highlighted
- Tags for other file types are ignored which weeds out even more irrelevant tags
- If you enable file type specific tags files this process is further optimized because vim-easytags doesn't have to ignore tags defined in other file types (since they will never be added to a file type specific tags file anyway)
- If you enable dynamic tags files and use them as project specific tags files (e.g. create a tags file in every project root directory) this is basically the best approach currently available; all irrelevant tags are not included in a project specific tags file, so vim-easytags will only have to process and highlight tags which are actually relevant to the project you're working on
If any of the hints I've provided in this reply help to the point where vim-easytags no longer interrupts your workflows, please report that so I can consider adding it to the documentation.
@jrk-: If deleting ~/.vimtags
solved the problem, then the size of the tags file was most likely the problem.
@xolox It was around 900K iirc. I guess that was too large. :)
I have the same issue.
when observing the thing with strace, I found, that while gvim/cursor is so slow strace prints really a lot of brk() calls (http://stackoverflow.com/questions/6988487/what-does-brk-system-call-do), where You can see, that the same calls are performed again and again:
brk(0x2c52000) = 0x2c52000
brk(0x3152000) = 0x3152000
brk(0x334b000) = 0x334b000
brk(0x3f45000) = 0x3f45000
brk(0x4b3f000) = 0x4b3f000
brk(0x5739000) = 0x5739000
brk(0x3f45000) = 0x3f45000
brk(0x4b3f000) = 0x4b3f000
brk(0x5739000) = 0x5739000
brk(0x3f45000) = 0x3f45000
brk(0x4b3f000) = 0x4b3f000
brk(0x5739000) = 0x5739000
brk(0x3f45000) = 0x3f45000
...
So I expect some kind of memory handling issue...
@diefans which version of vim? 7.4 has a new "faster" regex engine which is absolutely horrible for easytags in its current form (yes it allocates millions of memory blocks per long regex) changing to the old engine resolves the issue: set regexpengine=0
an alternative is changing easytags to use syntax keyword instead of syntax match.
my version is 7.4 indeed.
after disabling easytags for a while I was giving it a try again by setting regexpengine=0
, but I still get tons of brk() calls...
how can I change easytags to use syntax keywords?
see https://github.com/xolox/vim-easytags/issues/68#issuecomment-28480981