perf: resolve unequal relative pairs without dual absolutize#44
Conversation
Pure relative inputs that miss the equal leading-parent lexical hit now share one cwd component stack and allocate only the result buffer. Hard-gate unequal rows drop from 5 allocs to 1; clean 0-alloc contracts unchanged.
Merging this PR will improve performance by ×2.3
|
Windows drive-relative paths are !has_root but carry a Prefix. The unequal relative optimization must not divert them through dual absolutize_with(cwd); ambient relative keeps try_absolutize (per-drive absolute). Restores the different drive-relative allocation hard-gate row.
There was a problem hiding this comment.
Pull request overview
This PR optimizes SugarPath::relative for the case where both inputs are pure relative paths but don’t share the same leading-parent (..) shape, by resolving both against a single ambient (or explicit) current directory as normal-component stacks and constructing only the final relative result buffer. This reduces intermediate allocations while preserving existing zero-allocation “clean path” contracts and Windows-specific drive-relative semantics.
Changes:
- Refactors lexical relative computation to reuse a shared “normal stack” representation and adds a shared-cwd stack-based resolution path for unequal leading-parent relative pairs.
- Adds a Windows regression test to ensure drive-relative inputs continue to use
try_absolutize(per-drivestd::path::absolute) rather than the pure-relative shared-cwd path. - Updates allocation hard-gate snapshots and records the optimization in the performance strategy PCR doc.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/impl_sugar_path.rs |
Implements stack-based shared-cwd resolution for pure-relative unequal leading-parent pairs and integrates it into the relative slow-path selection logic. |
tests/relative_lexical.rs |
Adds a Windows-only test to validate ambient relative behavior for drive-relative inputs against try_absolutize composition. |
benchmarks/allocations/x86_64-unknown-linux-gnu.snap |
Updates the gated allocation rows to reflect reduced allocations for unequal leading-parent relative workloads. |
benchmarks/allocations/x86_64-pc-windows-msvc.snap |
Updates the gated allocation rows to reflect reduced allocations for unequal leading-parent relative workloads on Windows. |
.agents/docs/performance-strategy.md |
Updates/clarifies remaining performance directions and records the unequal leading-parent improvement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reuse LexicalRelativeShape from the ambient relative gate when resolving unequal pairs against cwd, so the unequal slow path does not scan each input twice.
Summary
relativeinputs that miss the equal leading-parent lexical hit now resolve both sides against one ambient (or explicit) cwd as normal-component stacks and build a single result buffer.PathBufs on the unequal leading-parent general path.cached_current_dir, Apple ARM64): ~50% wall-time reduction on shallow unequal, ~35% on p99 unequal (directional local evidence).Test plan
cargo test --locked --workspaceand--all-featurescargo clippy --locked --workspace --all-targets --all-features -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --all-features --no-depscargo allocsprint: unequal 1/0; clean normalize/absolutize/descendant relative still 0cargo allocs --checkon updated hard-gate snaps (requested-byte columns still historical until a native--write)tests/relative_lexicalunequal + deep unequal + no-cwd child process still pass