Skip to content

f_has(): fast-path for features not in has_list[]#19550

Closed
mattn wants to merge 1 commit intovim:masterfrom
mattn:optimize-f_has-fast-path
Closed

f_has(): fast-path for features not in has_list[]#19550
mattn wants to merge 1 commit intovim:masterfrom
mattn:optimize-f_has-fast-path

Conversation

@mattn
Copy link
Member

@mattn mattn commented Mar 2, 2026

When querying has() for things like patch-*, vim_starting, gui_running, etc., these were only checked after a linear scan through all ~198 entries in has_list[]. Since none of them exist in that table, the scan always came up empty before reaching the actual check.

This moves those runtime-checked features before the has_list[] scan so we skip the unnecessary work.

Called has() 1000000 times per item, averaged over 3 runs:

feature master fast-path change
patch-9.1.0001 6.04s 4.84s -19.8%
patch1 5.69s 4.08s -28.3%
vim_starting 5.77s 4.66s -19.3%
gui_running 5.82s 4.36s -25.0%
clipboard_working 6.01s 4.45s -25.9%
linux 3.99s 4.08s no change
eval 4.37s 4.47s no change
xterm_clipboard 6.06s 6.27s no change
writebackup 5.74s 5.66s no change
nonexistent 6.32s 6.06s no change
total 55.80s 48.93s -12.3%

Items that hit the fast-path are 20-28% faster. No regression for items looked up via has_list[].

Move runtime-checked features (patch-*, vim_starting, ttyin, etc.)
before the has_list[] linear scan so that common queries like
has('patch-9.1.xxxx') skip the ~198-entry table lookup entirely.
@chrisbra
Copy link
Member

chrisbra commented Mar 2, 2026

thanks

@chrisbra chrisbra closed this in 327e0e3 Mar 2, 2026
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Mar 3, 2026
…ure scan

Problem:  The has() function is slow because it performs a linear scan
          of the feature list for every call.
Solution: Move common runtime checks and the patch-version parser to the
          beginning of the f_has() function (Yasuhiro Matsumoto).

closes: vim/vim#19550

vim/vim@327e0e3

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Mar 3, 2026
…ure scan

Problem:  The has() function is slow because it performs a linear scan
          of the feature list for every call.
Solution: Move common runtime checks and the patch-version parser to the
          beginning of the f_has() function (Yasuhiro Matsumoto).

closes: vim/vim#19550

vim/vim@327e0e3

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Mar 3, 2026
…ure scan

Problem:  The has() function is slow because it performs a linear scan
          of the feature list for every call.
Solution: Move common runtime checks and the patch-version parser to the
          beginning of the f_has() function (Yasuhiro Matsumoto).

closes: vim/vim#19550

vim/vim@327e0e3

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Mar 3, 2026
…ure scan (#38135)

Problem:  The has() function is slow because it performs a linear scan
          of the feature list for every call.
Solution: Move common runtime checks and the patch-version parser to the
          beginning of the f_has() function (Yasuhiro Matsumoto).

closes: vim/vim#19550

vim/vim@327e0e3

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
ZieMcd pushed a commit to ZieMcd/neovim that referenced this pull request Mar 6, 2026
…ure scan (neovim#38135)

Problem:  The has() function is slow because it performs a linear scan
          of the feature list for every call.
Solution: Move common runtime checks and the patch-version parser to the
          beginning of the f_has() function (Yasuhiro Matsumoto).

closes: vim/vim#19550

vim/vim@327e0e3

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants