Skip to content

Commit 83e8cf3

Browse files
committed
Use timers to identify slow[est] parts of vim-easytags
See also #80 where I suggested to add accurate timing to the vim-easytags plug-in. Here it is :-). This is still quite rudimentary but it's already an improvement over what was there before!
1 parent a18d9f7 commit 83e8cf3

File tree

3 files changed

+85
-21
lines changed

3 files changed

+85
-21
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ This option defines the pathname of the script that contains the Python implemen
265265

266266
## Troubleshooting
267267

268+
## vim-easytags is slow!
269+
270+
Yes, I know. I'm trying to make it faster but that's far from trivial. In the process of trying to speed up vim-easytags I've added reporting of elapsed time in several ways. If Vim seems very slow and you suspect this plug-in might be the one to blame, increase Vim's verbosity level:
271+
272+
:set vbs=1
273+
274+
Every time the plug-in executes it will time how long the execution takes and add the results to Vim's message history, which you can view by executing the [:messages] [messages] command. If you want a more fine grained impression of the time spent by vim-easytags on various operations you can call the `xolox#easytags#why_so_slow()` function:
275+
276+
:call xolox#easytags#why_so_slow()
277+
easytags.vim 3.6.4: Timings since you started Vim:
278+
- 0.094937 seconds updating tags
279+
- 1.850201 seconds highlighting tags
280+
- 0.035167 seconds highlighting tags using ':syntax match')
281+
- 0.493910 seconds highlighting tags using ':syntax keyword')
282+
- 0.413160 seconds filtering tags for highlighting (stage 1)
283+
- 0.141747 seconds filtering tags for highlighting (stage 2)
284+
268285
### `:HighlightTags` only works for the tags file created by `:UpdateTags`
269286

270287
If you want to create tags files and have their tags highlighted by the `easytags.vim` plug-in then you'll have to create the tags file with certain arguments to Exuberant Ctags:
@@ -299,12 +316,6 @@ Once or twice now in several years I've experienced Exuberant Ctags getting into
299316

300317
$ pkill -KILL ctags
301318

302-
If Vim seems very slow and you suspect this plug-in might be the one to blame, increase Vim's verbosity level:
303-
304-
:set vbs=1
305-
306-
Every time the plug-in executes it will time how long the execution takes and add the results to Vim's message history, which you can view by executing the [:messages] [messages] command.
307-
308319
### Failed to highlight tags because pattern is too big!
309320

310321
If the `easytags.vim` plug-in fails to highlight your tags and the error message mentions that the pattern is too big, your tags file has grown too large for Vim to be able to highlight all tagged identifiers! I've had this happen to me with 50 KB patterns because I added most of the headers in `/usr/include/` to my tags file. Internally Vim raises the error [E339: Pattern too long] [e339] and unfortunately the only way to avoid this problem once it occurs is to reduce the number of tagged identifiers...

autoload/xolox/easytags.vim

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
" Vim script
22
" Author: Peter Odding <[email protected]>
3-
" Last Change: July 9, 2014
3+
" Last Change: July 19, 2014
44
" URL: http://peterodding.com/code/vim/easytags/
55

6-
let g:xolox#easytags#version = '3.6.3'
6+
let g:xolox#easytags#version = '3.6.4'
77
let g:xolox#easytags#default_pattern_prefix = '\C\<'
88
let g:xolox#easytags#default_pattern_suffix = '\>'
99

10+
if !exists('s:timers_initialized')
11+
let g:xolox#easytags#update_timer = xolox#misc#timer#resumable()
12+
let g:xolox#easytags#highlight_timer = xolox#misc#timer#resumable()
13+
let g:xolox#easytags#syntax_match_timer = xolox#misc#timer#resumable()
14+
let g:xolox#easytags#syntax_keyword_timer = xolox#misc#timer#resumable()
15+
let g:xolox#easytags#syntax_filter_stage_1_timer = xolox#misc#timer#resumable()
16+
let g:xolox#easytags#syntax_filter_stage_2_timer = xolox#misc#timer#resumable()
17+
let s:timers_initialized = 1
18+
endif
19+
1020
" Plug-in initialization. {{{1
1121

1222
function! xolox#easytags#initialize(min_version) " {{{2
@@ -155,14 +165,15 @@ endfunction
155165

156166
function! xolox#easytags#update(silent, filter_tags, filenames) " {{{2
157167
let async = xolox#misc#option#get('easytags_async', 0)
168+
call g:xolox#easytags#update_timer.start()
158169
try
159170
let have_args = !empty(a:filenames)
160171
let starttime = xolox#misc#timer#start()
161172
let cfile = s:check_cfile(a:silent, a:filter_tags, have_args)
162173
let tagsfile = xolox#easytags#get_tagsfile()
163174
let command_line = s:prep_cmdline(cfile, tagsfile, a:filenames)
164175
if empty(command_line)
165-
return
176+
return 0
166177
endif
167178
" Pack all of the information required to update the tags in
168179
" a Vim dictionary which is easy to serialize to a string.
@@ -191,6 +202,8 @@ function! xolox#easytags#update(silent, filter_tags, filenames) " {{{2
191202
return 1
192203
catch
193204
call xolox#misc#msg#warn("easytags.vim %s: %s (at %s)", g:xolox#easytags#version, v:exception, v:throwpoint)
205+
finally
206+
call g:xolox#easytags#update_timer.stop()
194207
endtry
195208
endfunction
196209

@@ -279,6 +292,7 @@ endfunction
279292
function! xolox#easytags#highlight() " {{{2
280293
" TODO This is a mess; Re-implement Python version in Vim script, benchmark, remove Python version.
281294
try
295+
call g:xolox#easytags#highlight_timer.start()
282296
" Treat C++ and Objective-C as plain C.
283297
let filetype = xolox#easytags#filetypes#canonicalize(&filetype)
284298
let tagkinds = get(s:tagkinds, filetype, [])
@@ -304,15 +318,19 @@ function! xolox#easytags#highlight() " {{{2
304318
" Get the list of tags when we need it and remember the results.
305319
let ctags_filetypes = xolox#easytags#filetypes#find_ctags_aliases(filetype)
306320
let filetypes_pattern = printf('^\(%s\)$', join(map(ctags_filetypes, 'xolox#misc#escape#pattern(v:val)'), '\|'))
321+
call g:xolox#easytags#syntax_filter_stage_1_timer.start()
307322
let taglist = filter(taglist('.'), "get(v:val, 'language', '') =~? filetypes_pattern")
323+
call g:xolox#easytags#syntax_filter_stage_1_timer.stop()
308324
endif
309325
" Filter a copy of the list of tags to the relevant kinds.
310326
if has_key(tagkind, 'tagkinds')
311327
let filter = 'v:val.kind =~ tagkind.tagkinds'
312328
else
313329
let filter = tagkind.vim_filter
314330
endif
331+
call g:xolox#easytags#syntax_filter_stage_2_timer.start()
315332
let matches = filter(copy(taglist), filter)
333+
call g:xolox#easytags#syntax_filter_stage_2_timer.stop()
316334
if matches != []
317335
" Convert matched tags to :syntax commands and execute them.
318336
let use_keywords_when = xolox#misc#option#get('easytags_syntax_keyword', 'auto')
@@ -326,6 +344,7 @@ function! xolox#easytags#highlight() " {{{2
326344
" keyword command when 1) we can do so without sacrificing
327345
" accuracy or 2) the user explicitly chose to sacrifice
328346
" accuracy in order to make the highlighting faster.
347+
call g:xolox#easytags#syntax_keyword_timer.start()
329348
let keywords = {}
330349
for tag in matches
331350
if s:is_keyword_compatible(tag)
@@ -341,8 +360,10 @@ function! xolox#easytags#highlight() " {{{2
341360
" tags that still need to be highlighted.
342361
call filter(matches, "!s:is_keyword_compatible(v:val)")
343362
endif
363+
call g:xolox#easytags#syntax_keyword_timer.stop()
344364
endif
345365
if !empty(matches)
366+
call g:xolox#easytags#syntax_match_timer.start()
346367
let matches = xolox#misc#list#unique(map(matches, 'xolox#misc#escape#pattern(get(v:val, "name"))'))
347368
let pattern = tagkind.pattern_prefix . '\%(' . join(matches, '\|') . '\)' . tagkind.pattern_suffix
348369
let template = 'syntax match %s /%s/ containedin=ALLBUT,%s'
@@ -354,6 +375,7 @@ function! xolox#easytags#highlight() " {{{2
354375
let msg = "easytags.vim %s: Failed to highlight %i %s tags because pattern is too big! (%i KB)"
355376
call xolox#misc#msg#warn(msg, g:xolox#easytags#version, len(matches), tagkind.hlgroup, len(pattern) / 1024)
356377
endtry
378+
call g:xolox#easytags#syntax_match_timer.stop()
357379
endif
358380
endif
359381
endif
@@ -373,6 +395,8 @@ function! xolox#easytags#highlight() " {{{2
373395
endif
374396
catch
375397
call xolox#misc#msg#warn("easytags.vim %s: %s (at %s)", g:xolox#easytags#version, v:exception, v:throwpoint)
398+
finally
399+
call g:xolox#easytags#highlight_timer.stop()
376400
endtry
377401
endfunction
378402

@@ -490,6 +514,17 @@ function! xolox#easytags#restore_automatic_updates() " {{{2
490514
endif
491515
endfunction
492516

517+
function! xolox#easytags#why_so_slow() " {{{2
518+
let message = [printf("easytags.vim %s: Timings since you started Vim:", g:xolox#easytags#version)]
519+
call add(message, printf(" - %s seconds updating tags", g:xolox#easytags#update_timer.format()))
520+
call add(message, printf(" - %s seconds highlighting tags", g:xolox#easytags#highlight_timer.format()))
521+
call add(message, printf(" - %s seconds highlighting tags using ':syntax match')", g:xolox#easytags#syntax_match_timer.format()))
522+
call add(message, printf(" - %s seconds highlighting tags using ':syntax keyword')", g:xolox#easytags#syntax_keyword_timer.format()))
523+
call add(message, printf(" - %s seconds filtering tags for highlighting (stage 1)", g:xolox#easytags#syntax_filter_stage_1_timer.format()))
524+
call add(message, printf(" - %s seconds filtering tags for highlighting (stage 2)", g:xolox#easytags#syntax_filter_stage_2_timer.format()))
525+
echo join(message, "\n")
526+
endfunction
527+
493528
" Public API for definition of file type specific dynamic syntax highlighting. {{{1
494529

495530
function! xolox#easytags#define_tagkind(object) " {{{2

doc/easytags.txt

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ Contents ~
3535
1. The |g:easytags_python_enabled| option
3636
2. The |g:easytags_python_script| option
3737
7. Troubleshooting |easytags-troubleshooting|
38+
8. vim-easytags is slow! |vim-easytags-is-slow|
3839
1. |:HighlightTags| only works for the tags file created by |:UpdateTags| |easytags-highlighttags-only-works-for-tags-file-created-by-updatetags|
3940
2. The plug-in complains that Exuberant Ctags isn't installed |easytags-plug-in-complains-that-exuberant-ctags-isnt-installed|
4041
3. Vim locks up while the plug-in is running |easytags-vim-locks-up-while-plug-in-is-running|
4142
4. Failed to highlight tags because pattern is too big! |easytags-failed-to-highlight-tags-because-pattern-is-too-big|
4243
5. The plug-in doesn't seem to work in Cygwin |easytags-plug-in-doesnt-seem-to-work-in-cygwin|
43-
8. Contact |easytags-contact|
44-
9. License |easytags-license|
45-
10. References |easytags-references|
44+
9. Contact |easytags-contact|
45+
10. License |easytags-license|
46+
11. References |easytags-references|
4647

4748
===============================================================================
4849
*easytags-introduction*
@@ -556,6 +557,32 @@ implementation of dynamic syntax highlighting.
556557
*easytags-troubleshooting*
557558
Troubleshooting ~
558559

560+
===============================================================================
561+
*vim-easytags-is-slow*
562+
vim-easytags is slow! ~
563+
564+
Yes, I know. I'm trying to make it faster but that's far from trivial. In the
565+
process of trying to speed up vim-easytags I've added reporting of elapsed time
566+
in several ways. If Vim seems very slow and you suspect this plug-in might be
567+
the one to blame, increase Vim's verbosity level:
568+
>
569+
:set vbs=1
570+
<
571+
Every time the plug-in executes it will time how long the execution takes and
572+
add the results to Vim's message history, which you can view by executing the
573+
|:messages| command. If you want a more fine grained impression of the time
574+
spent by vim-easytags on various operations you can call the
575+
'xolox#easytags#why_so_slow()' function:
576+
>
577+
:call xolox#easytags#why_so_slow()
578+
easytags.vim 3.6.4: Timings since you started Vim:
579+
- 0.094937 seconds updating tags
580+
- 1.850201 seconds highlighting tags
581+
- 0.035167 seconds highlighting tags using ':syntax match')
582+
- 0.493910 seconds highlighting tags using ':syntax keyword')
583+
- 0.413160 seconds filtering tags for highlighting (stage 1)
584+
- 0.141747 seconds filtering tags for highlighting (stage 2)
585+
<
559586
-------------------------------------------------------------------------------
560587
*easytags-highlighttags-only-works-for-tags-file-created-by-updatetags*
561588
:HighlightTags only works for the tags file created by :UpdateTags ~
@@ -618,15 +645,6 @@ command (available on most UNIX systems):
618645
>
619646
$ pkill -KILL ctags
620647
<
621-
If Vim seems very slow and you suspect this plug-in might be the one to blame,
622-
increase Vim's verbosity level:
623-
>
624-
:set vbs=1
625-
<
626-
Every time the plug-in executes it will time how long the execution takes and
627-
add the results to Vim's message history, which you can view by executing the
628-
|:messages| command.
629-
630648
-------------------------------------------------------------------------------
631649
*easytags-failed-to-highlight-tags-because-pattern-is-too-big*
632650
Failed to highlight tags because pattern is too big! ~

0 commit comments

Comments
 (0)