Cache cwd path absolutization via once_cell_cache feature for a large increase in effective parallelism#4016
Closed
alexander-beedie wants to merge 1 commit into
Closed
Conversation
cwd path absolutization via once_cell_cache feature (up to 35% speedup)cwd path absolutization via once_cell_cache feature (up to 35% type-checking speedup)
cwd path absolutization via once_cell_cache feature (up to 35% type-checking speedup)cwd path absolutization via once_cell_cache feature for a large increase in effective parallelism
…-checking speedup)
12d6449 to
94f9cd2
Compare
Contributor
|
wow, nice! |
Contributor
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D110782573. |
Member
|
Awesome! Thank you @alexander-beedie :) |
yangdanny97
approved these changes
Jul 6, 2026
yangdanny97
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
|
@samwgoldman merged this pull request in 197d490. |
Contributor
Author
You're welcome ;) |
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.
For a one-line/no-code update this unlocks a lot of extra speed/parallelism 😄
Example:
sparkandstreamlitnow type-check ~35% faster on my machine 🚀I think this might also positively impact #3993 by reducing
getcwdsyscalls (these are likely not a big contributor though), so would be marginally additive to #3994.Summary
Overview
Profiling across the
mypy_primercorpus showedstd::env::current_dir()syscalls eating a surprising amount of CPU. TheAbsolutizetrait delegates to thepath-absolutizecrate, which callscurrent_dir()on everyabsolutize(), even for already-absolute paths.A project absolutizes once per module (plus per glob/config site), so a large one can issue thousands of unnecessary
getcwdsyscalls per run.This is especially damaging under parallelism:
current_dir()is a process-global syscall that contends across threads, so the cost/impact grows with thread count.Solution
Enabling
path-absolutize's "once_cell_cache" feature resolves thecwdjust once, via a thread-safe cell, and reuses it. This completely eliminates the parallel contention without touching any pyrefly code/logic.Test Plan
No type-checking logic (or actual code!) was changed.
All test results are identical before/after.
Benchmarks1
Timed single-threaded (
j1) and multi-threaded (mt) across ~60 of themypy_primerprojects.mods= how many modules are in the project.old= pyrefly on main branch.new= main + this PR.Results below omit trivially-sized or very fast-running projects.
Time in seconds, min of 4 runs after warmup.
Footnotes
Test machine: Apple Silicon M3 Max. ↩