Skip to content

refactor(cache): replace papaya with dashmap#1214

Merged
Boshen merged 1 commit into
mainfrom
perf/reduce-binary-size
Jun 17, 2026
Merged

refactor(cache): replace papaya with dashmap#1214
Boshen merged 1 commit into
mainfrom
perf/reduce-binary-size

Conversation

@Boshen

@Boshen Boshen commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

Replaces papaya with dashmap for the resolver's path / tsconfig cache. papaya's lock-free implementation compiles to more code than dashmap's sharded RwLock, so the swap shrinks the published binary and turns out a touch faster — even though dashmap pulls more dependency crates.

Binary size

Measured on the darwin-arm64 .node (built with mimalloc, like CI):

size Δ
papaya (baseline) 1,685,744
dashmap 1,669,536 −16,208 (−1.0%)

cdylib (without mimalloc): 1,601,872 → 1,585,680 (−16,192).

Performance

CodSpeed reports a net +4.12%, with 4 benchmarks faster, 17 untouched, and none regressed — so the lock-free → sharded-lock change is a win in practice, not a trade-off (the restored memoized-hash IdentityHasher avoids re-hashing, and dashmap's reads skip papaya's epoch-reclamation overhead):

benchmark base head
pm/npm-flat 960.7 µs 907.9 µs +5.81%
pm/bun-isolated 1.1 ms 1.1 ms +3.97%
package_json_deserialization/medium 17.1 µs 16.5 µs +3.45%
resolver_real[resolve from symlinks] 37.2 ms 36 ms +3.27%

(The CodSpeed suite is single-threaded, so it measures resolution speed rather than worst-case parallel cache contention.)

Port details

  • The paths set keeps CachedPath as the key with IdentityHasher, which feeds the hash memoized on CachedPath straight through — no path duplication, no re-hashing. Because IdentityHasher only accepts a single write_u64, the set can't be probed by a borrowed &Path through dashmap's Borrow-based get; Cache::value instead looks it up via the raw-api (precomputed hash + OsStr equality on the shard) — the direct analog of the Equivalent lookup the papaya set used, still zero-alloc and unsafe-free.
  • Cache::value keeps the parent-chain recursion unlocked (as papaya's non-locking .pin() allowed), then dedups the final insert via entry() so concurrent first-touches of a path converge to one shared Arc — preserving the identity the canonicalized / node_modules weak-pointer caches depend on.
  • Removes the now-dead borrowed_path module (Equivalent borrowed-lookup helper).

Validation

cargo test + cargo test --all-features (unit + integration + PnP), cargo clippy --all-features --all-targets -D warnings, cargo check --target s390x-unknown-linux-gnu, cargo shear, and node --run build + node --run test on the rebuilt .node — all green. CI green across all platforms incl. big-endian, wasm, and CodSpeed.

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.70%. Comparing base (c55a3e1) to head (150f951).

Files with missing lines Patch % Lines
src/cache/cache_impl.rs 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1214      +/-   ##
==========================================
- Coverage   93.77%   93.70%   -0.07%     
==========================================
  Files          22       21       -1     
  Lines        4227     4197      -30     
==========================================
- Hits         3964     3933      -31     
- Misses        263      264       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Boshen Boshen changed the title perf: reduce binary size refactor(cache): replace papaya with dashmap Jun 17, 2026
@Boshen Boshen force-pushed the perf/reduce-binary-size branch from 9796f3d to 3162d63 Compare June 17, 2026 14:12

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdaf9a475e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Cargo.toml Outdated
papaya's lock-free implementation compiles to more code than dashmap's
sharded RwLock, so swapping it shrinks the published darwin-arm64 .node by
~16 KB (1,685,744 -> 1,669,536) even though dashmap pulls more dependency
crates.

The paths set keeps CachedPath as the key and IdentityHasher, which feeds
the hash memoized on CachedPath straight through. Since IdentityHasher only
accepts a single write_u64, the set can't be probed by a borrowed &Path via
dashmap's Borrow-based get, so Cache::value looks it up through the raw-api
(precomputed hash + OsStr equality on the shard) -- the direct analog of the
Equivalent lookup the papaya set used, and still zero-alloc.

Cache::value keeps the parent-chain recursion unlocked, as papaya's
non-locking .pin() guard allowed, then dedups the final insert with entry()
so concurrent first-touches of a path converge to one shared Arc, preserving
the identity the canonicalized / node_modules weak-pointer caches rely on.
Removes the now-dead borrowed_path module.

Trade-off: cache reads move from lock-free to sharded-lock. All tests pass
but concurrent throughput is not benchmarked.
@Boshen Boshen force-pushed the perf/reduce-binary-size branch from 3162d63 to 150f951 Compare June 17, 2026 14:22
@codspeed-hq

codspeed-hq Bot commented Jun 17, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.12%

⚡ 4 improved benchmarks
✅ 17 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
pm/npm-flat 960.7 µs 907.9 µs +5.81%
pm/bun-isolated 1.1 ms 1.1 ms +3.97%
medium 17.1 µs 16.5 µs +3.45%
resolver_real[resolve from symlinks] 37.2 ms 36 ms +3.27%

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 perf/reduce-binary-size (150f951) with main (c55a3e1)

Open in CodSpeed

Footnotes

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

@Boshen Boshen merged commit 3365d86 into main Jun 17, 2026
19 checks passed
@Boshen Boshen deleted the perf/reduce-binary-size branch June 17, 2026 14:45
@oxc-guard oxc-guard Bot mentioned this pull request Jun 17, 2026
Boshen pushed a commit that referenced this pull request Jun 17, 2026
## 🤖 New release

* `oxc_resolver`: 11.21.0 -> 11.21.1
* `oxc_resolver_napi`: 11.21.0 -> 11.21.1

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[11.21.1](v11.21.0...v11.21.1)
- 2026-06-17

### <!-- 1 -->🐛 Bug Fixes

- *(tsconfig)* walk up for non-TS and `allowJs`-off `.js` importers
([#1216](#1216)) (by
@shulaoda)
- *(tsconfig)* honor explicit non-TS extensions in `include`
([#1213](#1213)) (by
@shulaoda)

### <!-- 2 -->🚜 Refactor

- *(cache)* replace papaya with dashmap
([#1214](#1214)) (by
@Boshen)

### <!-- 6 -->🧪 Testing

- verify node_modules canonicalization across layouts
([#1200](#1200)) (by
@Boshen)

### Contributors

* @shulaoda
* @Boshen
</blockquote>



</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: oxc-guard[bot] <276638029+oxc-guard[bot]@users.noreply.github.com>
@oxc-guard oxc-guard Bot mentioned this pull request Jun 17, 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.

1 participant