[vim/vim] Speed up executable() on MS-Windows with a prefix search (PR #21416)

2 views
Skip to first unread message

mattn

unread,
4:09 AM (7 hours ago) 4:09 AM
to vim/vim, Subscribed

On MS-Windows, executable() queries every $PATHEXT extension in every $PATH directory, although most directories do not contain the command at all. This patch first does a single FindFirstFileExW() search for "name*" in each directory and skips it when nothing matches. When the search is inconclusive, or the path or extensions are unusual (".", wildcards, ":", trailing dot/space, non-alphanumeric extensions, fewer than 3 extensions), the existing per-extension checks are used as before.

Benchmark (54 $PATH entries, 11 $PATHEXT entries, 'shell' is cmd.exe, average per call):

case before after
full $PATH, command not found 5.0 ms 1.5 ms
full $PATH, found in System32 1.6 ms 0.75 ms
full $PATH, found (git) 130 us 85 us
full $PATH, name with extension (git.exe) 129 us 126 us
$PATH=System32 only, not found 111 us 42 us
$PATH=System32 only, found 39 us 73 us

The last row is the worst case: when the command is in the first, large directory, the extra prefix search adds a few tens of microseconds. In normal setups the skipped directories outweigh this.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/21416

Commit Summary

  • 80bb9a2 Speed up executable() on MS-Windows with a prefix search

File Changes

(2 files)

Patch Links:

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21416@github.com>

Reply all
Reply to author
Forward
0 new messages