You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(paths): decide common-shape path containment without pathlib's parent walk #5135
status/acceptedHuman scope approval; verify the issue's approval record and review contact before work.type/performanceLatency, throughput, memory, install time.
Python's pathlib containment methods are slow on hot paths. relative_to walks every parent of the base and builds a path object per step, and is_relative_to does the same. A warm install at t50 makes about 25,900 relative_to and 12,500 is_relative_to calls, which slows install, audit and the no-op install.
Proposal
Add explicit helpers to the path owner utils/paths.py (relative_to, relative_posix, is_within) with semantics identical to pathlib. They decide only the common shape, absolute paths of one class rooted at POSIX / or Windows X:\, by comparing normalized strings, and defer every other shape to pathlib unchanged. The ten owner files that make hot containment calls move to the helpers. Every resolve()/realpath call stays where it is, so each containment check makes the same filesystem calls in the same order; only the pure comparison step after resolution changes.
Done when
A fuzz-equivalence property test runs in CI and is green.
Each helper has red-first equivalence cells.
One pre-declared 15-pair run on all 3 OSes at the PR head (the full 15 pairs on every OS).
Decision: approve
Area: project
Scope: replace pathlib relative/containment hot calls in 10 owner files with one explicit utils/paths helper of identical semantics, making the same syscalls at every containment check.
Done when: fuzz-equivalence CI property test green; red-first equivalence cells per helper; one pre-declared 15-pair 3-OS run at the PR head (full 15 pairs on every OS); W3b design note; QL H8.
Out of scope: any path cache or memo; stdlib patching; changes to containment decisions.
Review contact: Daniel Meppiel (@danielmeppiel)
#5132 merged (c4071af): APM's path checks now use one string-based helper for "is this path inside that directory" instead of building and comparing pathlib objects each time. Same answers, including for symlinks and ..; less work per file.
CPU at tree-50 (50 packages), paired p50 over 15 interleaved pairs, main a725feb vs cc25bda (a final 30-pair rerun on macOS for the install cells):
Journey
Linux
macOS
Windows
No-op install
-18.2%
-23.0%
-11.3%
Audit
-15.2%
0.0%
-9.8%
Install, warm cache
-10.3%
-7.4% (30-pair rerun)
-6.5%
Cold install
-7.7%
-7.5% (30-pair rerun)
-4.6%
No cell regressed. Requests and process counts are identical between base and new. Runs: Linux 45299448704, macOS 45299452582 plus final rerun 45304713784 and 45304718096, Windows 45299455907, 45299459920, 45299463934.
Done in #5132 (merged c4071af): explicit string-based containment helpers in utils/paths.py with pathlib-identical semantics. Measured numbers were posted above (t50 no-op -18.2% / -23.0% / -11.3% CPU on Linux / macOS / Windows).
status/acceptedHuman scope approval; verify the issue's approval record and review contact before work.type/performanceLatency, throughput, memory, install time.
Activity
danielmeppiel commentedon Nov 23, 2026
Decision: approve
Area: project
Scope: replace pathlib relative/containment hot calls in 10 owner files with one explicit utils/paths helper of identical semantics, making the same syscalls at every containment check.
Done when: fuzz-equivalence CI property test green; red-first equivalence cells per helper; one pre-declared 15-pair 3-OS run at the PR head (full 15 pairs on every OS); W3b design note; QL H8.
Out of scope: any path cache or memo; stdlib patching; changes to containment decisions.
Review contact: Daniel Meppiel (@danielmeppiel)
danielmeppiel commentedon Nov 24, 2026
#5132 merged (c4071af): APM's path checks now use one string-based helper for "is this path inside that directory" instead of building and comparing pathlib objects each time. Same answers, including for symlinks and
..; less work per file.CPU at tree-50 (50 packages), paired p50 over 15 interleaved pairs, main a725feb vs cc25bda (a final 30-pair rerun on macOS for the install cells):
No cell regressed. Requests and process counts are identical between base and new. Runs: Linux 45299448704, macOS 45299452582 plus final rerun 45304713784 and 45304718096, Windows 45299455907, 45299459920, 45299463934.
danielmeppiel commentedon Nov 24, 2026
Done in #5132 (merged c4071af): explicit string-based containment helpers in utils/paths.py with pathlib-identical semantics. Measured numbers were posted above (t50 no-op -18.2% / -23.0% / -11.3% CPU on Linux / macOS / Windows).