Skip to content

[codex] Reuse prehashed resolver paths#13975

Draft
hardfist wants to merge 4 commits into
mainfrom
codex/prehash-resolver-path-deps
Draft

[codex] Reuse prehashed resolver paths#13975
hardfist wants to merge 4 commits into
mainfrom
codex/prehash-resolver-path-deps

Conversation

@hardfist
Copy link
Copy Markdown
Contributor

@hardfist hardfist commented May 9, 2026

Summary

  • Reuse resolver-provided precomputed path hashes when converting file and missing dependencies into ArcPath sets.
  • Add an ArcPath::from_path_buf_with_hash constructor and make ArcPath equality check the cached hash before comparing full paths.
  • Skip JavaScript module pre-walk passes when a module has no declarations/statements that those passes can act on.
  • Reuse the resolved module rule resource path across rule matching instead of recomputing it for each nested rule.
  • Update the resolver dependency to include cached package-json path joins.
  • Temporarily point rspack_resolver at the resolver PR branch so this draft can compile against the new API.

Why

build_module_graph receives dependency paths from rspack_resolver, deduplicates them, and then converts them into Rspack's prehashed ArcPath sets. Before this change, those paths were hashed again during conversion. This PR uses the prehashed resolver context from rstackjs/rspack-resolver#206 to avoid that extra full Path hash work.

The parser walk change removes two no-op JavaScript pre-walk traversals for modules where the pass cannot create bindings or module import/export dependencies. This produced a measurable instruction-count reduction locally, though it is still below the requested 10% target.

The rule matcher change hoists ResourceData::path() once per rule set/single-rule match so sync and async rule checks can reuse the same &str while preserving the existing matching order and fallback behavior.

The resolver dependency update avoids joining package.json paths repeatedly from the same cached directory during package-json reads and dependency recording.

Dependency

Depends on rstackjs/rspack-resolver#206. Before this can be marked ready, replace the temporary git dependency with the published resolver version containing ResolvePreHashedContext.

Micro-Optimization Progress

Target benchmark: rust@build_module_graph
Measurement mode: local Criterion plus Callgrind/CodSpeed Valgrind fork
Primary metric: Callgrind Ir for the benchmark useful segment

Commit Benchmark Mode Before After Delta Checks Notes
0394d0afcf rust@build_module_graph Criterion vs parent [176.32 ms 184.60 ms 193.61 ms] [172.44 ms 191.84 ms 218.00 ms] no significant change cargo check -p rspack_paths -p rspack_core; cargo test -p rspack_paths Resolver prehash reuse; CodSpeed reported no performance change.
7a21e93b80 rust@build_module_graph Callgrind Ir 4,380,134,836 4,217,447,382 -3.7% cargo fmt --check; cargo check -p rspack_plugin_javascript; cargo test -p rspack_plugin_javascript --lib Skips empty JS module pre-walk passes. Criterion short run: [172.89 ms 177.90 ms 183.45 ms], no statistically significant change.
f7df7f257b rust@build_module_graph Callgrind Ir 4,217,447,382 4,215,709,867 -0.04% cargo fmt --check; cargo check -p rspack_core; cargo test -p rspack_core module_rules Hoists rule resource path lookup. Test filter compiled successfully but matched 0 tests.
745d1cd351 rust@build_module_graph Callgrind Ir 4,215,709,867 4,177,020,822 -0.92% cargo check -p rspack_core; resolver cargo fmt --check; resolver cargo check; resolver cargo test package_json Updates to resolver c5d3b9df, which caches package-json path joins. Resolver full cargo test was attempted: 124 passed, 6 PnP fixture tests failed with NotFound(...).

Validation

  • cargo check -p rspack_paths -p rspack_core
  • cargo test -p rspack_paths
  • cargo fmt --check
  • cargo check -p rspack_plugin_javascript
  • cargo test -p rspack_plugin_javascript --lib
  • cargo check -p rspack_core
  • cargo test -p rspack_core module_rules
  • cargo check -p rspack_core
  • Resolver: cargo fmt --check
  • Resolver: cargo check
  • Resolver: cargo test package_json

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 Binary Size-limit

Comparing 0394d0a to test: split benchmark case entrypoints (#13971) by hardfist

❌ Size increased by 4.00KB from 61.92MB to 61.92MB (⬆️0.01%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 9, 2026

Merging this PR will not alter performance

✅ 34 untouched benchmarks
⏩ 25 skipped benchmarks1


Comparing codex/prehash-resolver-path-deps (0394d0a) with main (81aa0bb)

Open in CodSpeed

Footnotes

  1. 25 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB 0
react-10k 5.7 MB 0
react-1k 826.3 KB 0
rome 1.6 MB 0
react-5k 2.7 MB 0
ui-components 4.8 MB 0

Generated by Rsdoctor GitHub Action

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.

1 participant