Skip to content

perf: add support for module.unsafeCache configuration#11898

Merged
SyMind merged 14 commits intomainfrom
module.unsafeCache
Oct 20, 2025
Merged

perf: add support for module.unsafeCache configuration#11898
SyMind merged 14 commits intomainfrom
module.unsafeCache

Conversation

@SyMind
Copy link
Copy Markdown
Member

@SyMind SyMind commented Oct 16, 2025

Summary

Add support for module.unsafeCache configuration

This PR implements the module.unsafeCache option to optimize build performance by controlling dependency tracking for node_modules.

Behavior

When module.unsafeCache is disabled (false)

  • Rspack watches all missingDependencies, fileDependencies, and contextDependencies returned by the resolver
  • Ensures complete dependency tracking for accurate rebuilds

When module.unsafeCache is enabled (default: /[\\/]node_modules[\\/]/)

  • Rspack assumes node_modules files are stable and won't change paths
  • Skips recording resolver dependencies (missingDependencies, fileDependencies, contextDependencies) for node_modules modules
  • Improves build performance

Differences from webpack

1. Incremental Module Graph Rebuilding

  • Even when module.unsafeCache: false, Rspack still caches the Dependency-Module relationship
  • This is because Rspack uses incremental algorithms for module graph reconstruction
  • Provides better performance while maintaining accuracy

2. Configuration Support

  • Not supported: Function-based module.unsafeCache (to avoid frequent Rust-JavaScript communication overhead)
  • Enhanced: Added Regex support for more flexible module matching
  • Supported: Boolean values (true/false)

Checklist

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

@netlify
Copy link
Copy Markdown

netlify bot commented Oct 16, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 08f6355
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/68f597f71cab6200082a0f2c

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Oct 16, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 16, 2025

📦 Binary Size-limit

Comparing 08f6355 to test: add warn while closing compiler with failure (#11909) by harpsealjs

🎉 Size decreased by 5.00KB from 47.67MB to 47.67MB (⬇️0.01%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Oct 16, 2025

CodSpeed Performance Report

Merging #11898 will not alter performance

Comparing module.unsafeCache (08f6355) with main (ceb5a7e)1

Summary

✅ 17 untouched

Footnotes

  1. No successful run was found on main (beafb11) during the generation of this report, so ceb5a7e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@SyMind SyMind changed the title feat: support module.unsafeCache perf: support module.unsafeCache Oct 17, 2025
@SyMind SyMind changed the title perf: support module.unsafeCache perf: add support for module.unsafeCache configuration Oct 17, 2025
@github-actions github-actions bot added release: performance release: performance related release(mr only) and removed release: feature release: feature related release(mr only) labels Oct 17, 2025
@SyMind SyMind marked this pull request as ready for review October 17, 2025 02:57
Copilot AI review requested due to automatic review settings October 17, 2025 02:57
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

Adds support for module.unsafeCache to control resolver dependency tracking for performance, with boolean and RegExp options, wired through schema, normalization, defaults, adapter, bindings, and core, plus docs and tests.

  • Schema/types accept boolean | RegExp; normalization/adapter pass-through to core
  • Defaults gate unsafeCache on cache, with node_modules-only behavior when true
  • Core applies predicate to skip resolver file/context/missing deps for matched modules; docs and tests added

Reviewed Changes

Copilot reviewed 22 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/docs/zh/config/module.mdx Documents module.unsafeCache behavior and defaults in Chinese
website/docs/en/config/module.mdx Documents module.unsafeCache behavior and defaults in English
tests/rspack-test/defaultsCases/mode/development.js Updates defaults snapshot to reflect unsafeCache in development with cache
tests/rspack-test/defaultsCases/default/base.js Asserts unsafeCache defaults to false when cache is disabled
tests/rspack-test/defaultsCases/cache/non-root.js Updates snapshot: unsafeCache true when cache filesystem enabled non-root
tests/rspack-test/defaultsCases/cache/cache.js Updates snapshot: unsafeCache true when cache enabled
tests/rspack-test/defaultsCases/cache/cache-filesystem.js Updates snapshot: unsafeCache true with filesystem cache
tests/rspack-test/configCases/unsafe-cache/regExp/rspack.config.js Adds test for RegExp predicate behavior on missingDependencies
tests/rspack-test/configCases/unsafe-cache/regExp/index.js Test entry for RegExp case
tests/rspack-test/configCases/unsafe-cache/enabled/rspack.config.js Adds test for boolean true behavior on dependency tracking
tests/rspack-test/configCases/unsafe-cache/enabled/index.js Test entry for boolean true case
packages/rspack/src/schema/config.ts Adds unsafeCache schema (boolean
packages/rspack/src/config/types.ts Adds unsafeCache to ModuleOptions type
packages/rspack/src/config/normalization.ts Wires unsafeCache through normalization
packages/rspack/src/config/defaults.ts Sets unsafeCache default based on cache setting
packages/rspack/src/config/adapter.ts Passes unsafeCache through to raw options
crates/rspack_core/src/options/module.rs Introduces UnsafeCachePredicate and field; debug adjustments
crates/rspack_core/src/compilation/make/graph_updater/repair/factorize.rs Applies predicate to elide resolver deps in FactorizeInfo
crates/rspack_binding_api/src/raw_options/raw_module/mod.rs Adds unsafe_cache to RawModuleOptions; implements predicate mapping and node_modules default
crates/rspack/src/builder/mod.rs Wires unsafe_cache in ModuleOptionsBuilder; debug macro import
crates/rspack/Cargo.toml Adds derive_more dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 17, 2025

📝 Benchmark detail: Open

Name Base (2025-10-17 2ccce25) Current Change
10000_big_production-mode_disable-minimize + exec 27.9 s ± 595 ms 27.8 s ± 418 ms -0.49 %
10000_development-mode + exec 1.59 s ± 18 ms 1.52 s ± 13 ms -4.23 %
10000_development-mode_hmr + exec 669 ms ± 6.9 ms 644 ms ± 11 ms -3.80 %
10000_development-mode_noop-loader + exec 2.55 s ± 46 ms 2.48 s ± 89 ms -2.75 %
10000_production-mode + exec 1.6 s ± 44 ms 1.6 s ± 29 ms +0.02 %
10000_production-mode_persistent-cold + exec 1.82 s ± 27 ms 1.76 s ± 22 ms -3.30 %
10000_production-mode_persistent-hot + exec 1.35 s ± 24 ms 1.28 s ± 56 ms -5.01 %
arco-pro_development-mode + exec 1.69 s ± 132 ms 1.68 s ± 70 ms -0.28 %
arco-pro_development-mode_hmr + exec 372 ms ± 2.6 ms 365 ms ± 0.84 ms -1.91 %
arco-pro_production-mode + exec 3.09 s ± 90 ms 3.14 s ± 92 ms +1.64 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.22 s ± 65 ms 3.17 s ± 96 ms -1.58 %
arco-pro_production-mode_persistent-cold + exec 3.21 s ± 111 ms 3.15 s ± 126 ms -1.80 %
arco-pro_production-mode_persistent-hot + exec 1.82 s ± 32 ms 1.81 s ± 49 ms -0.63 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.14 s ± 92 ms 3.12 s ± 75 ms -0.85 %
large-dyn-imports_development-mode + exec 1.81 s ± 35 ms 1.77 s ± 27 ms -1.95 %
large-dyn-imports_production-mode + exec 1.8 s ± 40 ms 1.81 s ± 18 ms +0.81 %
threejs_development-mode_10x + exec 1.42 s ± 40 ms 1.43 s ± 33 ms +0.99 %
threejs_development-mode_10x_hmr + exec 909 ms ± 9 ms 899 ms ± 14 ms -1.18 %
threejs_production-mode_10x + exec 4.39 s ± 93 ms 4.34 s ± 84 ms -1.05 %
threejs_production-mode_10x_persistent-cold + exec 4.57 s ± 62 ms 4.53 s ± 56 ms -0.78 %
threejs_production-mode_10x_persistent-hot + exec 3.93 s ± 34 ms 3.88 s ± 31 ms -1.26 %
10000_big_production-mode_disable-minimize + rss memory 8782 MiB ± 322 MiB 8706 MiB ± 233 MiB -0.86 %
10000_development-mode + rss memory 828 MiB ± 41.6 MiB 781 MiB ± 59 MiB -5.58 %
10000_development-mode_hmr + rss memory 1005 MiB ± 54.2 MiB 915 MiB ± 39.9 MiB -8.97 %
10000_development-mode_noop-loader + rss memory 1163 MiB ± 22 MiB 1076 MiB ± 66.2 MiB -7.52 %
10000_production-mode + rss memory 756 MiB ± 29.2 MiB 766 MiB ± 34.6 MiB +1.37 %
10000_production-mode_persistent-cold + rss memory 915 MiB ± 109 MiB 868 MiB ± 26.1 MiB -5.15 %
10000_production-mode_persistent-hot + rss memory 894 MiB ± 51.1 MiB 800 MiB ± 16.5 MiB -10.55 %
arco-pro_development-mode + rss memory 669 MiB ± 43.9 MiB 676 MiB ± 37.9 MiB +1.14 %
arco-pro_development-mode_hmr + rss memory 560 MiB ± 57.5 MiB 529 MiB ± 10.1 MiB -5.65 %
arco-pro_production-mode + rss memory 786 MiB ± 121 MiB 770 MiB ± 103 MiB -2.08 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 771 MiB ± 67.3 MiB 779 MiB ± 85.1 MiB +1.05 %
arco-pro_production-mode_persistent-cold + rss memory 894 MiB ± 108 MiB 893 MiB ± 103 MiB -0.13 %
arco-pro_production-mode_persistent-hot + rss memory 724 MiB ± 138 MiB 700 MiB ± 47 MiB -3.33 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 792 MiB ± 75 MiB 798 MiB ± 61.3 MiB +0.71 %
large-dyn-imports_development-mode + rss memory 878 MiB ± 12.1 MiB 802 MiB ± 29.1 MiB -8.57 %
large-dyn-imports_production-mode + rss memory 710 MiB ± 15 MiB 709 MiB ± 11.7 MiB -0.12 %
threejs_development-mode_10x + rss memory 804 MiB ± 80.5 MiB 823 MiB ± 114 MiB +2.33 %
threejs_development-mode_10x_hmr + rss memory 1051 MiB ± 76.5 MiB 1013 MiB ± 116 MiB -3.59 %
threejs_production-mode_10x + rss memory 1043 MiB ± 194 MiB 965 MiB ± 143 MiB -7.50 %
threejs_production-mode_10x_persistent-cold + rss memory 1061 MiB ± 57.4 MiB 1065 MiB ± 91.2 MiB +0.44 %
threejs_production-mode_10x_persistent-hot + rss memory 833 MiB ± 34.2 MiB 827 MiB ± 46.2 MiB -0.70 %

@SyMind SyMind force-pushed the module.unsafeCache branch from 472de9a to 4bf039e Compare October 17, 2025 05:11
@SyMind SyMind force-pushed the module.unsafeCache branch from 4ec6b73 to cc180c2 Compare October 17, 2025 05:49
ahabhgk
ahabhgk previously approved these changes Oct 17, 2025
stormslowly
stormslowly previously approved these changes Oct 17, 2025
@SyMind SyMind dismissed stale reviews from stormslowly and ahabhgk via ec14e24 October 20, 2025 01:49
@SyMind SyMind force-pushed the module.unsafeCache branch from e3ad8ee to ab5e366 Compare October 20, 2025 01:53
@SyMind SyMind merged commit 8500d7a into main Oct 20, 2025
69 of 72 checks passed
@SyMind SyMind deleted the module.unsafeCache branch October 20, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants