Skip to content
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

MatchParen is soooo slow when ft=raku #12168

Closed
AN3223 opened this issue Mar 16, 2023 · 7 comments
Closed

MatchParen is soooo slow when ft=raku #12168

AN3223 opened this issue Mar 16, 2023 · 7 comments

Comments

@AN3223
Copy link

AN3223 commented Mar 16, 2023

Steps to reproduce

  1. vim --clean
  2. Type some opening & closing parenthesis, I used (((((((())))))))
  3. Move the cursor back and forth, everything works fine
  4. :set ft=raku
  5. :source $VIMRUNTIME/plugin/matchparen.vim
  6. Move the cursor back and forth, it's sooooooo slow!

Expected behaviour

Ideally there should be no lag or delay

Version of Vim

9.0 Included patches: 1-1337

Environment

OS: Alpine Linux edge
Terminal: foot
$TERM: foot
Shell: busybox ash

Logs and stack traces

No response

@AN3223 AN3223 added the bug label Mar 16, 2023
@AN3223
Copy link
Author

AN3223 commented Mar 16, 2023

As a workaround I put this in my vimrc: autocmd FileType raku NoMatchParen

@chrisbra
Copy link
Member

Can you please do profiling to find out where matchparen is slow? Also, does it work better if you disable syntax highlighting? In that case using :syntime to get syntax profiling would be helpful. Also, consider setting g:matchparen_timeout variable to a lower value.

@AN3223
Copy link
Author

AN3223 commented Mar 17, 2023

Can you please do profiling to find out where matchparen is slow?

Here is one where I manually moved the cursor around and observed the lag while profiling (full profile in this gist):

echo '(((((((())))))))' | vim --clean --cmd 'profile start profile.log' --cmd 'profile func *' --cmd 'profile file *' -c 'set ft=raku' -c 'source $VIMRUNTIME/plugin/matchparen.vim' -

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
   16   1.211936   1.211520  <SNR>14_Highlight_Matching_Pair()
    2   0.018945   0.000264  <SNR>6_SynSet()
    1   0.002460   0.000744  dist#script#DetectFiletype()
    1   0.002007   0.001652  <SNR>3_LoadFTPlugin()
    1   0.001716             <SNR>10_DetectFromText()
   16   0.000416             <SNR>14_Remove_Matches()
    1   0.000401   0.000139  <SNR>4_LoadIndent()
                             <SNR>10_DetectFromHashBang()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
   16   1.211936   1.211520  <SNR>14_Highlight_Matching_Pair()
    1              0.001716  <SNR>10_DetectFromText()
    1   0.002007   0.001652  <SNR>3_LoadFTPlugin()
    1   0.002460   0.000744  dist#script#DetectFiletype()
   16              0.000416  <SNR>14_Remove_Matches()
    2   0.018945   0.000264  <SNR>6_SynSet()
    1   0.000401   0.000139  <SNR>4_LoadIndent()
                             <SNR>10_DetectFromHashBang()

Here is one where I just did everything in -c commands (full profile in this gist). I think this one did not replicate the lag but I am including it just in case it is any use:

echo '(((((((())))))))' | vim --clean --cmd 'profile start profile.log' --cmd 'profile func *' --cmd 'profile file *' -c 'set ft=raku' -c 'source $VIMRUNTIME/plugin/matchparen.vim' -c 'normal 15l' -c 'profdel func *' -c 'profdel file *' -c 'qa!' -

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    2   0.018842   0.000203  <SNR>6_SynSet()
    1   0.003234   0.002868  <SNR>3_LoadFTPlugin()
    1   0.001636   0.001030  dist#script#DetectFiletype()
    1   0.000606             <SNR>10_DetectFromText()
    1   0.000361   0.000131  <SNR>4_LoadIndent()
                             <SNR>10_DetectFromHashBang()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1   0.003234   0.002868  <SNR>3_LoadFTPlugin()
    1   0.001636   0.001030  dist#script#DetectFiletype()
    1              0.000606  <SNR>10_DetectFromText()
    2   0.018842   0.000203  <SNR>6_SynSet()
    1   0.000361   0.000131  <SNR>4_LoadIndent()
                             <SNR>10_DetectFromHashBang()

Also, does it work better if you disable syntax highlighting?

Yes, there's no lag when :set syntax=off

In that case using :syntime to get syntax profiling would be helpful.

Here, I recorded this using the reproduction steps, just moving the cursor back and forth over some parenthesis:

  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
  2.528968   2336   0       0.002479    0.001083  rakuNumber         [A-Za-z_\xC0-\xFF0-9]\@1<!\%(\%(\_^\|\s\|[^*\a]\)\@1<=[-+]\)\?\%(\%(\d\|__\@!\)*[._]\@1<!
  2.387905   2336   0       0.002068    0.001022  rakuTypeConstraint \%([.^]\|^\s*\)\@<![A-Za-z_\xC0-\xFF0-9]\@1<!\%([A-Za-z_\xC0-\xFF][-']\)\@2<!is\%([A-Za-z
  2.207283   2336   0       0.002984    0.000945  rakuQuoteQStart    \%(:\|\%(sub\|role\)\s\)\@5<![Qq]\@=
  1.351689   2336   0       0.001257    0.000579  rakuKeywordStart   \%(\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)\%([A-Za-
  1.283480   2336   0       0.002544    0.000549  rakuNumber         [A-Za-z_\xC0-\xFF0-9]\@1<!\%(\%(\_^\|\s\|[^*\a]\)\@1<=[-+]\)\?0[obxd]\@=
  1.214515   2336   0       0.003213    0.000520  rakuMatchBare      /\@1<!\%(\%(\_^\|[!\[,=~|&/:({]\|\^\?fff\?\^\?\|=>\|\<\%(if\|unless\|while\|when\|where\|
  1.202711   2336   0       0.001632    0.000515  rakuTypeConstraint \%([.^]\|^\s*\)\@<!\a\@=\%(does\|as\|but\|trusts\|of\|returns\|handles\|where\|augment\|s
  1.125465   2336   0       0.001822    0.000482  rakuNumber         [A-Za-z_\xC0-\xFF0-9]\@1<!\%(\%(\%(\_^\|\s\|[^*\a]\)\@1<=[-+]\)\?Inf\|NaN\)
  1.094686   2336   0       0.001936    0.000469  rakuIdentifier     \%(::\)\@2<=\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)
  0.852982   2336   0       0.001523    0.000365  rakuType           \%(::\)\@2<!\%(SeekType\%(::SeekFromBeginning\|::SeekFromCurrent\|::SeekFromEnd\)\|Order\
  0.189978   11722  11722   0.000172    0.000016  rakuClose          [\])]
  0.096979   2336   0       0.000116    0.000042  rakuReduceOp       \%(^\|\s\|(\)\@1<=!*\%([RSXZ\[]\)*[&RSXZ]\?\[\+(\?\%(\d\|[@%$][.?^=[:alpha:]]\)\@!\%(\.\|
  0.083155   2336   0       0.000919    0.000036  rakuSetOp          R\?(\%([-^.+|&]\|[<>][=+]\?\|cont\|elem\))
  0.080661   2336   0       0.002819    0.000035  rakuPodDelimRegion ^\z(\s*\)\zs=begin\>\ze\s*\%(pod\|item\|nested\|\u\+\)\>
  0.080262   2336   0       0.000134    0.000034  rakuDeclare        [.^]\@1<!\<\%(macro\|sub\|submethod\|method\|module\|class\|role\|package\|enum\|grammar\
  0.078902   2336   0       0.000139    0.000034  rakuStringAuto     \.\@1<!\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)\ze\%
  0.077348   2336   0       0.000103    0.000033  rakuHyperOp        [^[:digit:][{('",:[:space:]][^[{('",:[:space:]]*\%(«\|<<\)
  0.074633   2336   0       0.002734    0.000032  rakuStringAuto     \.\@1<!\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)p5\ze
  0.074542   2336   0       0.000090    0.000032  rakuStringAuto     \.\@1<!\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)\ze\s
  0.074027   2336   0       0.000538    0.000032  rakuStringAngle    \%(\<\%(enum\|for\|any\|all\|none\)\>\s*(\?\s*\)\@<=<\%(<\|=>\|\%([=-]\{1,2}>\|[=-]\{2}\)
  0.073919   2336   0       0.000107    0.000032  rakuContext        \%(\$\|@\|%\|&\)(\@=
  0.073724   2336   0       0.000137    0.000032  rakuVariable       [@$%&]\?[@&$%]\$*\%(::\|\%(\%([.^*?=!~]\|:\@1<!::\@!\)[A-Za-z_\xC0-\xFF]\)\|[A-Za-z_\xC0-
  0.072552   2336   0       0.003071    0.000031  rakuPodAbbrRegion  ^\s*\zs=\ze\%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)
  0.070758   2336   0       0.000068    0.000030  rakuIdentifier     \%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)\%(::\)\@=
  0.070158   2336   0       0.000122    0.000030  rakuOperator       [-+/*~?|=^!%&,<>».;\\∈∉∋∌∩∪≼≽⊂⊃⊄⊅⊆⊇⊈⊉⊍⊎⊖∅∘]
  0.068219   2336   0       0.000215    0.000029  rakuOperator       \%(\s\|^\)\@1<=\%(xx=\)
  0.067632   2336   0       0.000231    0.000029  rakuMatchStart_tr  \.\@1<!\<tr\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\)\@!
  0.066067   2336   0       0.000281    0.000028  rakuStringAngle    \%((\s*\|=\s\+\)\@<=<\%(<\|=>\|\%([=-]\{1,2}>\|[=-]\{2}\)\)\@!
  0.065920   2336   0       0.000387    0.000028  rakuStringAngle    \%(\s\|[<+~=!]\)\@<!<\%(<\|=>\|\%([=-]\{1,2}>\|[=-]\{2}\)\)\@!
  0.065787   2336   0       0.000280    0.000028  rakuStringAngle    [<+~=!]\@1<!<\%(\s\|<\|=>\|\%([=-]\{1,2}>\|[=-]\{1,2}\)\)\@!
  0.065743   2336   0       0.000088    0.000028  rakuIdentifier     \%([A-Za-z_\xC0-\xFF]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\@=\)*\)
  0.065654   2336   0       0.000394    0.000028  rakuDeclareRegex   [.^]\@1<!\<\%(regex\|rule\|token\)\>
  0.064274   2336   0       0.002775    0.000028  rakuPodDelimRegion ^\z(\s*\)\zs=begin\>\ze\s*code\>
  0.064073   2336   0       0.000077    0.000027  rakuMatchStart_m   \.\@1<!\<\%(mm\?\|rx\)\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\)\@!
  0.063486   2336   0       0.000098    0.000027  rakuMatchStart_s   \.\@1<!\<[sS]\%([A-Za-z_\xC0-\xFF0-9]\|[-'][A-Za-z_\xC0-\xFF]\)\@!
  0.062428   2336   0       0.000126    0.000027  rakuStringAngle    \%(^\s*\)\@<=<\%(<\|=>\|\%([=-]\{1,2}>\|[=-]\{2}\)\)\@!
  0.062089   2336   0       0.000099    0.000027  rakuBareSigil      [@$%&]\%(\s*\%([,)}=]\|where\>\)\)\@=
  0.061309   2336   0       0.000084    0.000026  rakuPreDeclare     [.^]\@1<!\<\%(multi\|proto\|only\)\>
  0.060839   2336   0       0.000085    0.000026  rakuPodParaRegion  ^\s*\zs=for\>\ze\s*\%(pod\|item\|nested\|\u\+\)\>
  0.060693   2336   0       0.000176    0.000026  rakuPodDelimRegion ^\z(\s*\)\zs=begin\>
  0.059845   2338   0       0.000302    0.000026  rakuRSXZOp         [RSXZ]:\@!\%(\a\@=\%(div\|mod\|gcd\|lcm\|xx\|x\|does\|but\|cmp\|leg\|eq\|ne\|gt\|ge\|lt\|
  0.058689   2338   0       0.000129    0.000025  rakuContext        \<\%(item\|list\|slice\|hash\)\>
  0.058289   2338   0       0.000123    0.000025  rakuMatchVarSigil  [$@]\%(<<\@!\)\@=
  0.045652   2338   0       0.003452    0.000020  rakuPodParaRegion  ^\s*\zs=for\>
  0.036649   2338   0       0.002647    0.000016  rakuPodAbbrRegion  ^\s*\zs=\zecode\>
  0.033487   2338   0       0.000047    0.000014  rakuOperator       :\@1<!::\@!!\?
  0.025198   2338   0       0.000187    0.000011  rakuOperator       \%(:\@1<!::\@2!\|::=\|\.::\)
  0.021890   1051   0       0.000062    0.000021  rakuPostHyperOp    \%(»\|>>\)
  0.019563   2338   0       0.000043    0.000008  rakuOperator       \%(&\.(\@=\|@\.\[\@=\|%\.{\@=\)
  0.016855   2338   0       0.000019    0.000007  rakuStringAngle    [<+~=!]\@1<!<\%(\s*$\)\@=
  0.015490   2338   0       0.000037    0.000007  rakuBlockLabel     ^\s*\zs\h\w*\s*::\@!\_s\@=
  0.015108   2338   0       0.000121    0.000006  rakuPackageTwigil  \%(::\)\@2<=\*
  0.014302   2338   0       0.000017    0.000006  rakuPodParaRegion  ^\s*\zs=for\>\ze\s*code\>
  0.001198   2338   0       0.000005    0.000001  rakuPodDelimRegion ^=begin\>\ze\s\+END\>
  0.000992   2338   0       0.000007    0.000000  rakuStringDQ       "
  0.000773   2338   0       0.000002    0.000000  rakuVariable       self
  0.000735   2338   0       0.000004    0.000000  rakuPodDirectRegion ^=encoding\>
  0.000709   2338   0       0.000014    0.000000  rakuStringAngle    <\%(\s*>\)\@=
  0.000680   2338   0       0.000001    0.000000  rakuVersion        \<v\d\+\%(\.\%(\*\|\d\+\)\)*+\?
  0.000650   2338   0       0.000003    0.000000  rakuHyperOp        »\%(\d\|[@%$][.?^=[:alpha:]]\)\@!\%(\.\|[^[{('".[:space:]]\)\+\%(«\|»\?\)
  0.000632   2338   0       0.000004    0.000000  rakuShebang        \%^#!.*
  0.000627   2338   0       0.000001    0.000000  rakuStringFrench   «
  0.000617   2338   0       0.000001    0.000000  rakuPodParaRegion  ^=for\>\ze\s\+END\>
  0.000599   2338   0       0.000003    0.000000  rakuHyperOp        «\%(\d\|[@%$][.?^=[:alpha:]]\)\@!\%(\.\|[^[{('".[:space:]]\)\+[«»]
  0.000581   2338   0       0.000004    0.000000  rakuStringAngles   <<=\@!
  0.000564   2338   0       0.000005    0.000000  rakuStringSQ       '
  0.000562   2338   0       0.000091    0.000000  rakuVarSlash       \$/
  0.000561   2338   0       0.000001    0.000000  rakuPodAbbrRegion  ^=\ze\%(pod\|item\|nested\|\u\+\)\>
  0.000553   2338   0       0.000007    0.000000  rakuVarMatch       \$¢
  0.000551   2338   0       0.000001    0.000000  rakuHyperOp        >>\%(\d\|[@%$][.?^=[:alpha:]]\)\@!\%(\.\|[^[{('".[:space:]]\)\+\%(<<\|\%(>>\)\?\)
  0.000543   2338   0       0.000015    0.000000  rakuBracketComment #[`|=]«««
  0.000511   2338   0       0.000001    0.000000  rakuBracketComment #[`|=]\[\[
  0.000503   2338   0       0.000003    0.000000  rakuHyperOp        <<\%(\d\|[@%$][.?^=[:alpha:]]\)\@!\%(\.\|[^[{('".[:space:]]\)\+\%(<<\|>>\)
  0.000498   2338   0       0.000003    0.000000  rakuBracketComment #[`|=]««
  0.000496   2338   0       0.000001    0.000000  rakuPodDirectRegion ^=\%(config\|use\)\>
  0.000489   2338   0       0.000003    0.000000  rakuComment        #.*
  0.000483   2338   0       0.000003    0.000000  rakuBracketComment #[`|=]{
  0.000476   2338   0       0.000015    0.000000  rakuBracketComment #[`|=]\[
  0.000476   2338   0       0.000001    0.000000  rakuPodAbbrRegion  ^=\zecomment\>
  0.000474   2338   0       0.000005    0.000000  rakuBracketComment #[`|=]<
  0.000473   2340   0       0.000004    0.000000  rakuBracketComment #[`|=](
  0.000473   2340   0       0.000001    0.000000  rakuVarExclam      \$!
  0.000468   2340   0       0.000001    0.000000  rakuBracketComment #[`|=]«
  0.000459   2340   0       0.000001    0.000000  rakuPodAbbrRegion  ^=\zeEND\>
  0.000457   2340   0       0.000001    0.000000  rakuBracketComment #[`|=](((
  0.000454   2340   0       0.000006    0.000000  rakuBracketComment #[`|=]<<<
  0.000447   2340   0       0.000001    0.000000  rakuVarNum         \$\d\+
  0.000347   2340   0       0.000004    0.000000  rakuBracketComment #[`|=]((
  0.000344   2340   0       0.000001    0.000000  rakuBracketComment #[`|=]<<
  0.000322   2340   0       0.000029    0.000000  rakuBracketComment #[`|=]{{{
  0.000298   2340   0       0.000005    0.000000  rakuBracketComment #[`|=]\[\[\[
  0.000293   2340   0       0.000001    0.000000  rakuBracketComment #[`|=]{{

 17.962639   223439

Also, consider setting g:matchparen_timeout variable to a lower value.

:let g:matchparen_timeout = 5 works OK

@AN3223
Copy link
Author

AN3223 commented Mar 19, 2023

I'm now realizing that typing quotation marks and parenthesis is noticeably slow too, even with NoMatchParen.

@chrisbra
Copy link
Member

Hm,
this seems to come from:

   16              1.066506     let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, timeout)

but I think it's not searchpairpos() that is notoriously bad, it's just that getting the correct syntax elements is, what makes it slow.

This also corresponds to your syntime profile. The individual patterns actually doen't look so bad, I just wonder why there were more than 2000 count matches for that reproduction steps.

@brammool
Copy link
Contributor

This appears to be a problem with the syntax highlighting. The file suggests to report at https://github.com/Raku/vim-raku/issues

@AN3223
Copy link
Author

AN3223 commented Mar 21, 2023

Ah okay, thank you. It appears there's already an issue there Raku/vim-raku#35, I guess I'll close this now.

@AN3223 AN3223 closed this as completed Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants