Skip to content

refactor: persistent cache remove lock#13589

Merged
jerrykingxyz merged 1 commit intomainfrom
jerry/cache
Apr 3, 2026
Merged

refactor: persistent cache remove lock#13589
jerrykingxyz merged 1 commit intomainfrom
jerry/cache

Conversation

@jerrykingxyz
Copy link
Copy Markdown
Contributor

@jerrykingxyz jerrykingxyz commented Apr 2, 2026

Summary

  • Persistent cache uses storage to save data in a certain order, so there is no need to use locks on storage.
trait Storage {
-  fn set(&self, scope: &'static str, key: Vec<u8>, value: Vec<u8>);
+  fn set(&mut self, scope: &'static str, key: Vec<u8>, value: Vec<u8>);
-  fn remove(&self, scope: &'static str, key: &[u8]);
+  fn remove(&mut self, scope: &'static str, key: &[u8]);
...
}
  • The persistent cache replace Arc with Box and remove the storage field from the Occassion struct.
struct MakeOccassion {
-  storage: ArcStorage
...
}
impl MakeOccassion {
-  fn save(...) {}
+  fn save(storage: &mut dyn Storage, ...) {}
...
}

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings April 2, 2026 08:46
@github-actions github-actions Bot added the team The issue/pr is created by the member of Rspack. label Apr 2, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 2, 2026

Merging this PR will improve performance by 2.87%

🎉 Hooray! codspeed-rust just leveled up to 4.4.1!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

⚡ 1 improved benchmark
✅ 15 untouched benchmarks
⏩ 19 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@create_chunk_ids 10.8 ms 10.5 ms +2.87%

Comparing jerry/cache (e8fb391) with main (713b798)

Open in CodSpeed

Footnotes

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors the persistent cache storage API to remove internal locking by switching storage mutation APIs to require &mut access, and by passing storage references explicitly through snapshot/occasion flows rather than sharing Arc handles.

Changes:

  • Refactor rspack_storage::Storage to use &mut self for mutating operations (set/remove/save/reset) and introduce BoxStorage in place of Arc<dyn Storage>.
  • Update persistent cache components (snapshot, build deps, occasions, cache hooks) to accept &dyn Storage / &mut dyn Storage parameters rather than storing clonable Arc storage handles.
  • Update rspack tools cache comparison utilities to work with BoxStorage and borrowed storage references.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rspack_tools/src/compare/mod.rs Switches comparison pipeline to BoxStorage and borrows storages for per-scope comparisons.
crates/rspack_tools/src/compare/snapshot.rs Updates snapshot comparison to accept borrowed storages (&dyn Storage).
crates/rspack_tools/src/compare/occasion/meta.rs Updates meta comparison to accept borrowed storages (&dyn Storage).
crates/rspack_tools/src/compare/occasion/make.rs Refactors make comparison to use new MakeOccasion API (storage passed into recovery).
crates/rspack_storage/src/lib.rs Changes Storage trait mutating methods to &mut self; replaces ArcStorage with BoxStorage.
crates/rspack_storage/src/memory/mod.rs Removes Mutex and updates implementation to match new Storage trait mutability requirements.
crates/rspack_storage/src/filesystem/mod.rs Removes Mutex around staged updates and updates APIs to &mut self mutation.
crates/rspack_core/src/cache/persistent/storage/mod.rs Re-exports BoxStorage and changes create_storage to return boxed storage.
crates/rspack_core/src/cache/persistent/snapshot/mod.rs Removes stored storage handle; requires explicit storage refs for add/remove/calc operations.
crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs Removes stored storage handle; passes storage into save/recovery.
crates/rspack_core/src/cache/persistent/occasion/make/mod.rs Removes stored storage handle; passes storage into save/recovery.
crates/rspack_core/src/cache/persistent/occasion/make/module_graph.rs Updates module graph save/recovery to use &mut dyn Storage / &dyn Storage.
crates/rspack_core/src/cache/persistent/build_dependencies/mod.rs Threads storage references through add/validate to match snapshot API.
crates/rspack_core/src/cache/persistent/mod.rs Updates PersistentCache to own BoxStorage and pass borrowed storage through all operations.
crates/rspack_core/src/cache/mod.rs Changes cache hook after_build_module_graph to require &mut self.
crates/rspack_core/src/cache/mixed.rs Adapts mixed cache implementation to the updated hook mutability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.3 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

📦 Binary Size-limit

Comparing e8fb391 to refactor(watcher): clean up stale entries from watch_patterns after unwatch (#13511) by Lee Jaeha / Adam

🎉 Size decreased by 9.59KB from 49.09MB to 49.08MB (⬇️0.02%)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

📝 Benchmark detail: Open

Name Base (e723074) Current Change
10000_big_production-mode_disable-minimize + exec 14.1 s ± 146 ms 14.1 s ± 353 ms +0.54 %
10000_development-mode + exec 930 ms ± 22 ms 936 ms ± 13 ms +0.71 %
10000_development-mode_hmr + stats 176 ms ± 6.4 ms 176 ms ± 5 ms -0.36 %
10000_development-mode_noop-loader + exec 1.95 s ± 98 ms 1.98 s ± 50 ms +1.76 %
10000_production-mode + exec 1.05 s ± 31 ms 1.06 s ± 32 ms +0.66 %
10000_production-mode_persistent-cold + exec 1.23 s ± 24 ms 1.22 s ± 22 ms -0.75 %
10000_production-mode_persistent-hot + exec 913 ms ± 21 ms 904 ms ± 17 ms -1.01 %
10000_production-mode_source-map + exec 1.23 s ± 19 ms 1.23 s ± 43 ms +0.32 %
arco-pro_development-mode + exec 1.34 s ± 81 ms 1.33 s ± 63 ms -0.92 %
arco-pro_development-mode_hmr + stats 38 ms ± 1 ms 38 ms ± 1 ms -0.57 %
arco-pro_production-mode + exec 2.49 s ± 90 ms 2.42 s ± 93 ms -2.79 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.53 s ± 85 ms 2.52 s ± 70 ms -0.54 %
arco-pro_production-mode_persistent-cold + exec 2.51 s ± 96 ms 2.5 s ± 63 ms -0.45 %
arco-pro_production-mode_persistent-hot + exec 1.37 s ± 35 ms 1.39 s ± 61 ms +1.32 %
arco-pro_production-mode_source-map + exec 2.93 s ± 40 ms 2.85 s ± 98 ms -2.66 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.49 s ± 70 ms 2.51 s ± 157 ms +0.92 %
bundled-threejs_development-mode + exec 182 ms ± 4.6 ms 181 ms ± 4.7 ms -0.77 %
bundled-threejs_production-mode + exec 213 ms ± 8.1 ms 212 ms ± 6.4 ms -0.09 %
large-dyn-imports_development-mode + exec 1.18 s ± 15 ms 1.18 s ± 32 ms 0.00 %
large-dyn-imports_production-mode + exec 1.32 s ± 30 ms 1.31 s ± 35 ms -0.71 %
threejs_development-mode_10x + exec 839 ms ± 45 ms 824 ms ± 21 ms -1.72 %
threejs_development-mode_10x_hmr + stats 116 ms ± 4.1 ms 117 ms ± 3.1 ms +0.61 %
threejs_production-mode_10x + exec 3.03 s ± 31 ms 3.05 s ± 66 ms +0.65 %
threejs_production-mode_10x_persistent-cold + exec 3.18 s ± 40 ms 3.18 s ± 17 ms 0.00 %
threejs_production-mode_10x_persistent-hot + exec 2.55 s ± 11 ms 2.54 s ± 27 ms -0.17 %
threejs_production-mode_10x_source-map + exec 3.8 s ± 33 ms 3.79 s ± 40 ms -0.16 %
10000_big_production-mode_disable-minimize + rss memory 1997 MiB ± 54.4 MiB 2018 MiB ± 92.8 MiB +1.02 %
10000_development-mode + rss memory 602 MiB ± 21 MiB 598 MiB ± 22.5 MiB -0.79 %
10000_development-mode_hmr + rss memory 818 MiB ± 33.7 MiB 818 MiB ± 46.8 MiB -0.01 %
10000_development-mode_noop-loader + rss memory 885 MiB ± 8.42 MiB 889 MiB ± 13 MiB +0.45 %
10000_production-mode + rss memory 544 MiB ± 14.4 MiB 539 MiB ± 17.5 MiB -0.84 %
10000_production-mode_persistent-cold + rss memory 722 MiB ± 11.9 MiB 739 MiB ± 16.6 MiB +2.33 %
10000_production-mode_persistent-hot + rss memory 691 MiB ± 7.84 MiB 703 MiB ± 22.4 MiB +1.77 %
10000_production-mode_source-map + rss memory 568 MiB ± 9.81 MiB 561 MiB ± 12.4 MiB -1.33 %
arco-pro_development-mode + rss memory 474 MiB ± 6.04 MiB 476 MiB ± 11.5 MiB +0.44 %
arco-pro_development-mode_hmr + rss memory 491 MiB ± 12.6 MiB 497 MiB ± 5.95 MiB +1.12 %
arco-pro_production-mode + rss memory 667 MiB ± 61.1 MiB 674 MiB ± 15.8 MiB +1.15 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 678 MiB ± 66.5 MiB 690 MiB ± 21.3 MiB +1.83 %
arco-pro_production-mode_persistent-cold + rss memory 733 MiB ± 26.9 MiB 743 MiB ± 8.65 MiB +1.32 %
arco-pro_production-mode_persistent-hot + rss memory 541 MiB ± 11.5 MiB 534 MiB ± 15 MiB -1.27 %
arco-pro_production-mode_source-map + rss memory 764 MiB ± 14.5 MiB 766 MiB ± 24.1 MiB +0.30 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 676 MiB ± 20.7 MiB 677 MiB ± 10.4 MiB +0.21 %
bundled-threejs_development-mode + rss memory 162 MiB ± 4.89 MiB 159 MiB ± 14.5 MiB -1.62 %
bundled-threejs_production-mode + rss memory 177 MiB ± 3.92 MiB 180 MiB ± 2.33 MiB +1.18 %
large-dyn-imports_development-mode + rss memory 590 MiB ± 24.5 MiB 587 MiB ± 46.1 MiB -0.40 %
large-dyn-imports_production-mode + rss memory 469 MiB ± 7.91 MiB 464 MiB ± 6.71 MiB -1.07 %
threejs_development-mode_10x + rss memory 540 MiB ± 16 MiB 539 MiB ± 19 MiB -0.14 %
threejs_development-mode_10x_hmr + rss memory 678 MiB ± 17.3 MiB 677 MiB ± 12.7 MiB -0.21 %
threejs_production-mode_10x + rss memory 720 MiB ± 19.3 MiB 715 MiB ± 10.9 MiB -0.70 %
threejs_production-mode_10x_persistent-cold + rss memory 850 MiB ± 13 MiB 848 MiB ± 28.1 MiB -0.20 %
threejs_production-mode_10x_persistent-hot + rss memory 607 MiB ± 7.12 MiB 611 MiB ± 6.69 MiB +0.75 %
threejs_production-mode_10x_source-map + rss memory 840 MiB ± 27.6 MiB 842 MiB ± 25.8 MiB +0.18 %

@jerrykingxyz jerrykingxyz merged commit e130804 into main Apr 3, 2026
74 of 76 checks passed
@jerrykingxyz jerrykingxyz deleted the jerry/cache branch April 3, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants