Skip to content

Conversation

@xolra0d
Copy link
Contributor

@xolra0d xolra0d commented Oct 18, 2025

Release notes summary - What our users need to know

The which command now filters files found in $PATH to include only executables.

Tasks after submitting


Done:

  1. Optimized search on Windows.
  2. Add is_executable check for found files in PATH.

Should resolve controversy in #16140

@xolra0d
Copy link
Contributor Author

xolra0d commented Oct 18, 2025

I've done some benchmarking and profiling.

Tested on the same device on Linux and Windows. My config:

$ which | length all files in PATH only executables in PATH
Linux 4043 4032
Windows 7731 1211

Results:

  1. Current which and which --all implementations perform well on Linux, yet suffer drastically on Windows.

    Perf diff Time
    Linux 5.957ms
    Windows 104.319ms

    This big difference is caused by path.is_file() check, which is extrimely expensive in Windows.

  2. After adding is_executable to algorithm and optimizing it, results are:

    Perf diff Old with path.is_file() New with path.is_executable() Percentage difference
    Linux 5.957ms 6.039ms 1.3%
    Windows 104.319ms 11.166ms −89.2%

    Note: old version with removed path.is_file() check was 12.319ms

Current is_executable implementation is the same as in is_executable crate, but removes another expensive check on Windows: path.exists().

@xolra0d xolra0d force-pushed the fix/list_only_executables branch from 6aaf1b2 to d3c09c8 Compare October 19, 2025 18:31
@xolra0d
Copy link
Contributor Author

xolra0d commented Oct 19, 2025

With windows crate, timeit {which} is 14ms.

@fdncred
Copy link
Contributor

fdncred commented Oct 20, 2025

Please add some text that describes what this does in the release notes section so it can be mentioned in the next release's notes.

@xolra0d
Copy link
Contributor Author

xolra0d commented Oct 20, 2025

Please add some text that describes what this does in the release notes section so it can be mentioned in the next release's notes.

Done

@fdncred
Copy link
Contributor

fdncred commented Oct 20, 2025

This is what I'm seeing on Windows. Of course, all of this depends on how many files you have in your path and what type of hard drives you have in your machine. I'm fine with this. Thanks!

Before

 use std/bench *
 bench { which } --rounds 100
╭──────┬────────────────────────╮
 mean  1sec 204ms 295µs 764ns 
 min   1sec 170ms 6µs 800ns   
 max   2sec 279ms 917µs 100ns 
 std   108ms 936µs 393ns      
╰──────┴────────────────────────╯

After

 use std/bench *
 bench { which } --rounds 100
╭──────┬───────────────────╮
 mean  276ms 41µs 368ns  
 min   270ms 169µs 400ns 
 max   360ms 372µs 200ns 
 std   9ms 478µs 767ns   
╰──────┴───────────────────╯

@fdncred fdncred merged commit e9d1df2 into nushell:main Oct 20, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.109.0 milestone Oct 20, 2025
@fdncred fdncred added A:file-system Related to commands and core nushell behavior around the file system notes:fixes Include the release notes summary in the "Bug fixes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. labels Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:file-system Related to commands and core nushell behavior around the file system notes:fixes Include the release notes summary in the "Bug fixes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants