aboutsummaryrefslogtreecommitdiff
path: root/runtime/syntax/python.vim
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-09-02 13:52:45 +0800
committerGitHub <noreply@github.com>2026-09-02 13:52:45 +0800
commit17acde8471af073c2724983e315c1b96247e006a (patch)
treea27a3167fcdb200c181deea767f63e4f8aca9928 /runtime/syntax/python.vim
parent90fc8946e8b421d0876124a3d45b1d37a0a0fd56 (diff)
downloadrneovim-17acde8471af073c2724983e315c1b96247e006a.tar.gz
rneovim-17acde8471af073c2724983e315c1b96247e006a.tar.bz2
rneovim-17acde8471af073c2724983e315c1b96247e006a.zip
vim-patch:9.2.1029: NFA regexp matching is slower than necessary (#41611)
Problem: NFA regexp matching is slower than necessary because addstate() tracks the recursion depth in a static variable. Solution: Pass the recursion depth as a function parameter so it stays in a register instead of being spilled to memory around every recursive call (Julien Voisin). addstate() is called very frequently and recursively. Storing the depth counter in a static variable forces the compiler to reload and store it in memory around each recursive call, since it cannot prove the recursion does not modify it. Passing it as a parameter keeps it in a register and drops the increment/decrement bookkeeping on every return path. The recursion limit behavior is unchanged. This reduces the instruction count of NFA matching by roughly 4% on state-heavy patterns. Benchmarking was done with something like: ``` set re=0 let s:word = repeat('abc123 def456 ghijk_lmnop QRSTUV wxyz0 ', 4000) for i in range(120) let s = s:word | let s = substitute(s, '\%#=2\(\a\+\)\(\d\+\)', '\2\1', 'g') let s = s:word | let s = substitute(s, '\%#=2\a\+\d\+', 'X', 'g') call matchstr(s:word, '\%#=2\(\a\|\d\|_\)\{3,}') endfor qa! ``` and `taskset -c 7 perf stat -e instructions ./vim -u NONE -N -X -es -S /tmp/nfabench/count.vim` closes: vim/vim#21202 https://github.com/vim/vim/commit/0e47c9612edfbcdd299dfacc78521d3ead88baa7 Co-authored-by: Julien Voisin <julien.voisin@dustri.org>
Diffstat (limited to 'runtime/syntax/python.vim')
0 files changed, 0 insertions, 0 deletions