aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_stringbuffer.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-09-03 11:07:44 +0800
committerGitHub <noreply@github.com>2026-09-03 11:07:44 +0800
commitb51a0b2dccb78151ae02b12ef32e0a6b623006d3 (patch)
tree285356f251a32e6cf8c03c68fee6acc62d1d80f3 /runtime/lua/vim/_stringbuffer.lua
parent7645d7e232123a060ccd16cf23bb1d86dcaf4203 (diff)
downloadrneovim-b51a0b2dccb78151ae02b12ef32e0a6b623006d3.tar.gz
rneovim-b51a0b2dccb78151ae02b12ef32e0a6b623006d3.tar.bz2
rneovim-b51a0b2dccb78151ae02b12ef32e0a6b623006d3.zip
vim-patch:9.2.1036: syntax highlighting is slower than necessary (#41644)
Problem: While advancing the syntax highlighting, store_current_state() calls syn_stack_find_entry() about once per parsed line, and that function rescans the state-cache list from its head every time. With the list capped at 1000 entries this linear rescan dominates the cost of highlighting a large file. Solution: Keep a cached position to the entry last located in the list and resume the scan from it when it is at or before the wanted line, advancing the finger as new states are stored (Julien Voisin). The list is sorted by line number, so when the remembered entry is at or before the wanted line the answer can only follow it, never precede it; resuming from there returns the same entry as a scan from the head. The "at or before" guard keeps this correct for any lookup order: a backward or random-access lookup whose remembered entry is past the wanted line falls back to a full scan. The pointer is cleared whenever an entry is freed, the array is reallocated or the block is freed, so it cannot dangle. Parsing the syntax of a 20000-line C file is about a third faster, a 5000-line file about a quarter faster, benchmarked via something like this: ``` call synID(1, 1, 1) " warm-up let s = reltime() for l in range(1, line('$')) | call synID(l, 1, 1) | endfor call writefile([reltimefloat(reltime(s))], $T) ``` closes: vim/vim#21166 https://github.com/vim/vim/commit/f1b454912996d6417acd0d738de0eb7b60902c56 Co-authored-by: Julien Voisin <julien.voisin@dustri.org>
Diffstat (limited to 'runtime/lua/vim/_stringbuffer.lua')
0 files changed, 0 insertions, 0 deletions