perf(pytest): cache path resolution to reduce discovery time for large test suites #25655
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.
fixes: #25348
Test discovery for large suites (~150k tests) shows 10x slowdown vs native pytest due to redundant path operations in
pytest_sessionfinishhook. Profiling indicates repeatedpathlib.Path.cwd()calls,os.fspath()conversions, and exception-based dictionary lookups dominate execution time.Changes
Caching infrastructure
_path_cache(node paths by id),_path_to_str_cache(string conversions),_CACHED_CWD(working directory)cached_fsdecode(): memoizedos.fspath()wrapper used for dictionary keys throughout tree buildingModified
get_node_path()Control flow optimization
try/except KeyErrorwithdict.get()in 5 hotpath locations:process_parameterized_test(),build_test_tree(),build_nested_folders()