Skip to content

perf: list directories instead of looking up each CLI path - #1483

Merged
dsherret merged 3 commits into
mainfrom
perf/literal-args-canonicalize
Nov 29, 2026
Merged

dsherret merged 3 commits into
mainfrom
perf/literal-args-canonicalize

Conversation

@dsherret

@dsherret dsherret commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1482. Most of the remaining time spent on a file path provided on the command line was statting and canonicalizing it.

When at least 8 of the paths are in the same directory, that directory is now canonicalized and listed once instead. A name listed as a regular file is not a symlink, and matching the listed name exactly means there is no casing difference to resolve, so neither call is necessary for it. Everything else (ex. directories, symlinks, casing differences, long paths) is looked up as before.

Listing a directory stops after 4 entries for each of the paths in it and then falls back to looking up each path. A test with 500 paths in a directory with 20,000 other files took 24.5ms instead of 23.6ms on Windows because of that.

dprint check with 500 file paths:

Before After
Windows 29.0ms 19.7ms
Linux 9.0ms 7.2ms
macOS 20.3ms 15.2ms

This also replaces dir_info on the environment with sys_traits' FsReadDir, so there's one way to list a directory and code can iterate the entries without collecting them.

@dsherret
dsherret merged commit c90c9bb into main Nov 29, 2026
6 checks passed
@dsherret
dsherret deleted the perf/literal-args-canonicalize branch November 29, 2026 21:33
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.

1 participant