Load each config file and probe each candidate only once in UpwardSearch - #4567
Open
alexander-beedie wants to merge 1 commit into
Open
Load each config file and probe each candidate only once in UpwardSearch#4567alexander-beedie wants to merge 1 commit into
UpwardSearch#4567alexander-beedie wants to merge 1 commit into
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D116264606. (Because this pull request was imported automatically, there will not be any future comments.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Overview
UpwardSearchwas doing unnecessary work; in most packages it wasn't a problem, but in some it could trigger a lot of redundant filesystem work by repeating a lot of load/stat calls on the same file(s).Solution
Optimise-out redundant IO/syscalls from
UpwardSearch(config load/probes) by using simpleSmallMapcaching, keyed by path.Before this PR, one config search would load the same file and stat the same candidate paths multiple times; now it only does each once.
Benchmarks1
There's a nice positive impact (on a limited number of packages), but it can be even more significant in corporate environments running endpoint security software.
Note: I was finally able to deterministically reproduce the increased cost of syscalls/IO caused by corporate endpoint security software introspection, so I've included it in the timings below (refs: #3993, #4017 (comment)).
The "taxed" columns show the additional overhead from endpoint security software. The real standout is
pywin32, with a ~5-6x overhead: ~0.74s normally, ~4.29 secs with the security software tax (reduced to ~2.83 secs with this PR).Speedups are almost entirely wall-clock, not CPU(load/stat costs are IO, not compute).
Projects with no
.venvbenefit most, as they have to discover their own interpreter, triggering redundant config loads. The "taxed" winners are projects with a largesite-packagestree which can trigger more syscalls.Test Plan
All existing unit tests pass, one new test added.
Was able to trigger the endpoint security cost via symlink indirection to the test corpus (eg: on macOS
/tmpis a symlink to/private/tmp, so/tmp/primer_repos/…crosses one symlink and/private/tmp/primer_repos/…crosses none; identical files/inodes/bytes, but it's the difference between a syscall costing ~0.7 µs or ~1.28 ms (~1000x more expensive, ouch 🚫)Footnotes
Test machine: Apple Silicon M3 Max (16 cores). ↩