Repository navigation
Open
Description
Looks like this plugin has issue with performance. I have delays when typing (up to 3 second).
I disabled all plugins and found than clojureSymbol regex take most time when working with clojure file.
vim version output
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 16 2016 15:08:31)
MacOS X (unix) version
Included patches: 1-41
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminfo
++builtin_terms +fork() +multi_lang +termresponse
+byte_offset -gettext -mzscheme +textobjects
+channel -hangul_input +netbeans_intg +timers
+cindent +iconv +num64 +title
-clientserver +insert_expand +packages -toolbar
+clipboard +job +path_extra +user_commands
+cmdline_compl +jumplist +perl +vertsplit
+cmdline_hist +keymap +persistent_undo +virtualedit
+cmdline_info +lambda +postscript +visual
+comments +langmap +printer +visualextra
+conceal +libcall +profile +viminfo
+cryptv +linebreak +python +vreplace
+cscope +lispindent -python3 +wildignore
+cursorbind +listcmds +quickfix +wildmenu
+cursorshape +localmap +reltime +windows
+dialog_con -lua +rightleft +writebackup
+diff +menu +ruby -X11
+digraphs +mksession +scrollbind -xfontset
-dnd +modify_fname +signs -xim
-ebcdic +mouse +smartindent -xpm
+emacs_tags -mouseshape +startuptime -xsmp
+eval +mouse_dec +statusline -xterm_clipboard
+ex_extra -mouse_gpm -sun_workshop -xterm_save
+extra_search -mouse_jsbterm +syntax
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -framework Cocoa -mmacosx-version-min=10.11 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.24.0_1/lib/perl5/5.24.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python -lruby.2.3.0 -lobjc -L/usr/local/Cellar/ruby/2.3.1_2/lib
My question is: can this regex be rewrited? Or this is already best solution?
Metadata
Metadata
Assignees
Labels
No labels

Activity
guns commentedon Oct 17, 2016
Hi @slonoed,
Could you provide an example file so I can confirm locally? This is the first I've heard of a serious performance issue with the syntax file.
rm-hull commentedon Oct 17, 2016
The clojureSymbol regex is consistently the top item for me too when running with
:syntime on.It is particularly bad if I have a long line of text and/or s-expressions, and try and delete a few characters using
x, especially if deleting an opening or closing double-quote on a string. There is perceptible lag, and if I hold the key down, i cannot predict how much text will be deleted - usually too much. IOW it is virtually unusable.Switching syntax off and deleting the same code fragment with
xworks absolutely fine.guns commentedon Oct 18, 2016
@rm-hull
I do believe that you and @slonoed are having issues, but I don't see them locally. I enjoy debugging performance issues, but I won't be able to do that without a reproducible example.
For instance,
On my machine, this operation is quite snappy, so I can only guess at what might be the problem.
morrifeldman commentedon Feb 7, 2017
I'm also seeing some typing and scrolling delays lately. I'm using neovim. I opened this file https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj and set
syntime onand scrolled up and down several times.clojureSymbol was easily the slowest call in the report.
TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN
7.938665 651229 631878 0.000352 0.000012 clojureSymbol \v%([a-zA-Z!$&_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&_+=|'<.>/?-]|[^\x00-\x7F]))[#:]@<!
1.513363 622798 568704 0.000057 0.000002 clojureError ]|}|)
0.575973 160840 24230 0.000035 0.000004 clojureNumber \v<[-+]?%(0|[1-9]\d|%(0|[1-9]\d*).\d*)%(M|[eE][-+]?\d+)?>
0.511449 142312 0 0.000037 0.000004 clojureNumber \v<[-+]?%(0|[1-9]\d*)/%(0|[1-9]\d*)>
0.459769 142312 0 0.000034 0.000003 clojureNumber \v\c<[-+]?36r[0123456789abcdefghijklmnopqrstuvwxyz]+>
0.448722 223648 86611 0.000051 0.000002 clojureKeyword \v<:{1,2}%([^ \n\r\t()[]{}";@^]+:@<!>
0.425358 150640 14030 0.000030 0.000003 clojureNumber \v<[-+]?%(0\o*|0x\x+|[1-9]\d*)N?>
guns commentedon Feb 7, 2017
Thanks @morrifeldman
Performance is still pretty good on my machine for the linked file, but I can see how scrolling would feel slow on a laptop.
I'll have a stab at optimizing the syntax file today.
guns commentedon Feb 8, 2017
Removing the 35 clojureNumber passes for each possible custom radix halves the syntax matching time overall.
Please try the following issue branch:
https://github.com/guns/vim-clojure-static/tree/issue-77
You can use the new syntax benchmark script
clj/bin/syntimeto compare syntax matching performance between HEAD and issue-77:$ cd vim-clojure-static/clj/bin/ $ ./syntime path-to-my-clojure-file.clj $ ls syntime report-2017-02-07-21-21-48.logrm-hull commentedon Feb 8, 2017
Hi, dwelling on:
I'm familiar with regexes in general, but not the vim-flavour specifically - and have a couple of questions:
\vdo?%(and)is a grouping?[^0\x00-\x7F]was for? unicode matching, maybe?If I remove the
[^0\x00-\x7F], this means the grouping can go, and replacea-zA-Zwith\aand0-9with\d,(not claiming this is valid or exactly equivalent, but you get the idea - is this viable?)
slowest 59 vs 928
average 5 vs 26
The (snipped) syntime comes in as:
vs previously:
guns commentedon Feb 9, 2017
Makes the pattern "very-magic", so closer to PCRE. See
:help \vIt is non capturing grouping, like
(?:). See:help \%(Yes. See 712be9a
Using the builtin char classes is a good idea. I'll have a look now.
rm-hull commentedon Feb 9, 2017
Urgh, I was getting frustrated searching google for for details on \v, %(, etc ... I didn't even consider the built-in docs... Oh well :)
Is there a \u (or equivalent) that can be used instead of [^\x00-\x7F] for unicode matching?
guns commentedon Feb 9, 2017
@rm-hull
Removing the multibyte character check and using character classes in place of character ranges produces the following pattern:
Note that
[\a]doesn't work in Vim; it matches two characters,\anda. Instead,[[:alpha:]]is equivalent to[a-zA-Z](ASCII only)Using the new
syntimescript, I get:ORIGINAL
WITH CHARACTER CLASSES
As you can see, there is no discernible performance difference after removing the multibyte check and replacing character ranges with character classes.
Furthermore, removing the
clojureSymbolpattern altogether would only reduce the running time to(0.118116 - 0.031737)/0.118116 =~ 73%of current performance.In contrast, the changes in the issue77 branch reduce the running time to 43% of current performance without changing the
clojureSymbolpattern. I hope to bring this benchmark down to 33% before merging into master.rm-hull commentedon Feb 9, 2017
I've been testing syntime with client.clj (from https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj) and this clearly taxes the
clojureSymbolmore than the generate.clj file - it is accounting for ~65% (= 0.051640 / 0.079156) of the total time:Removing it entirely, the total time drops from 0.79156 to 0.026007:
Where I put the carat indicator:
does this need to be
+(one or more) - can the quantifier be removed, so it matches exactly once?similarly, can the
:?be blended into[a-zA-Z0-9!#$%&*_+=|'<.>/?-]?Is it just that it is doing unnecessary backtracking?
rm-hull commentedon Feb 9, 2017
Actually, it seems like
@<!may be the culprit ... from the vim help:Without knowing the full impact of removing
@<!from the end of the regex, the total time is less than half of previousrm-hull commentedon Feb 9, 2017
@guns Oh, I should say all the ponderings/investigations of
clojureSymbolare with your issue77 branch changes appliedguns commentedon Feb 10, 2017
@rm-hull
Nice catch! Looks like
@1<!will give us the performance boost we want while keeping the intent of the pattern unchanged:guns commentedon Feb 10, 2017
Branch
issue-77now does syntax matching three times faster on average thanmaster. There are still a few small optimizations that can be made, and I am in the process of adding test cases for symbols.rm-hull commentedon Mar 11, 2017
@guns - any thoughts as to when that branch will get merged into master?
devth commentedon Mar 16, 2017
I too have noticed perf issues with Clojure syntax on a 2-month-old top-of-the-line MacBook Pro using regular vim.
Amazing work, looking forward to this being merged!
For those using neovim - does perf improve over regular vim? I'm thinking of switching.
devth commentedon Apr 7, 2017
Hi @guns, is https://github.com/guns/vim-clojure-static/tree/issue-77 ready to merge?
NoahTheDuke commentedon May 28, 2018
I hate to pile on, but I'd love to see some progress in this arena. Manually merging in some of the changes from issue-77 is great, but it's always nice to be official.