Skip to content

perf: resolve unequal relative pairs without dual absolutize#44

Merged
hyfdev merged 4 commits into
mainfrom
opt/general-path-algo
Jul 12, 2026
Merged

perf: resolve unequal relative pairs without dual absolutize#44
hyfdev merged 4 commits into
mainfrom
opt/general-path-algo

Conversation

@hyfdev

@hyfdev hyfdev commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Pure relative relative inputs 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.
  • Avoids cloning cwd twice and allocating two intermediate absolute PathBufs on the unequal leading-parent general path.
  • Allocation hard gate: unequal shallow/p99 rows 5 alloc → 1 alloc (0 realloc). Clean-path 0-alloc contracts unchanged.
  • Same-machine Criterion (cached_current_dir, Apple ARM64): ~50% wall-time reduction on shallow unequal, ~35% on p99 unequal (directional local evidence).
  • PCR: replace consumer-backed remaining list with library general-path directions and record this improvement.

Test plan

  • cargo test --locked --workspace and --all-features
  • cargo clippy --locked --workspace --all-targets --all-features -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --all-features --no-deps
  • Local cargo allocs print: unequal 1/0; clean normalize/absolutize/descendant relative still 0
  • CI Linux/Windows cargo allocs --check on updated hard-gate snaps (requested-byte columns still historical until a native --write)
  • tests/relative_lexical unequal + deep unequal + no-cwd child process still pass

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.
@codspeed-hq

codspeed-hq Bot commented Jul 12, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.3

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 9 improved benchmarks
✅ 207 untouched benchmarks
⏩ 30 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory relative/borrowed_receiver/natural_result/rolldown_shapes[relative_unequal_leading_parents] 203 B 42 B ×4.8
Memory relative/borrowed_receiver/pathbuf_result/rolldown_shapes[relative_unequal_leading_parents] 203 B 42 B ×4.8
Memory relative/borrowed_receiver/natural_result/rolldown_shapes[relative_p99_depth_unequal_parents] 270 B 69 B ×3.9
Memory relative/borrowed_receiver/pathbuf_result/rolldown_shapes[relative_p99_depth_unequal_parents] 270 B 69 B ×3.9
Simulation relative/borrowed_receiver/natural_result/rolldown_shapes[relative_unequal_leading_parents] 11.1 µs 7.3 µs +51.28%
Simulation relative/borrowed_receiver/pathbuf_result/rolldown_shapes[relative_unequal_leading_parents] 11.2 µs 7.4 µs +51.24%
Simulation relative/borrowed_receiver/natural_result/rolldown_shapes[relative_p99_depth_unequal_parents] 13.2 µs 9.7 µs +36.4%
Simulation relative/borrowed_receiver/pathbuf_result/rolldown_shapes[relative_p99_depth_unequal_parents] 13.4 µs 9.8 µs +36.36%
Simulation string 255.8 ns 226.7 ns +12.87%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing opt/general-path-algo (c97039f) with main (530e9c0)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

hyfdev added 2 commits July 12, 2026 17:29
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.
@hyfdev hyfdev marked this pull request as ready for review July 12, 2026 10:06
Copilot AI review requested due to automatic review settings July 12, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-drive std::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.

Comment thread src/impl_sugar_path.rs Outdated
Reuse LexicalRelativeShape from the ambient relative gate when resolving
unequal pairs against cwd, so the unequal slow path does not scan each
input twice.
@hyfdev hyfdev merged commit 7599911 into main Jul 12, 2026
9 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants