Skip to content

Conversation

@2heal1
Copy link
Member

@2heal1 2heal1 commented Nov 20, 2025

Summary

Support shared tree shaking .

It support two modes: runtime-infer | server-calc to satisfy different demands.

View this discusstion for more details .

Related links

Checklist

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

@netlify
Copy link

netlify bot commented Nov 20, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3282b3d
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6970d7bea0561d00084d0bd2

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Nov 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

📦 Binary Size-limit

Comparing b33c235 to refactor: improve runtime module macro (#12941) by harpsealjs

❌ Size increased by 216.38KB from 48.34MB to 48.55MB (⬆️0.44%)

@2heal1 2heal1 force-pushed the feat/shared-treeshake branch from a55f482 to 4bccd0f Compare November 20, 2025 07:44
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 20, 2025

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/shared-treeshake (b33c235) with main (bacc120)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@2heal1 2heal1 force-pushed the feat/shared-treeshake branch from 2219929 to 3c0a94e Compare December 9, 2025 08:28
…shaking

fix incorrect module name in shared config and test cases
change async process_module to sync using block_on for better performance
update shared exports optimization to handle side effects properly
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

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 825.4 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.2 MB 0

Generated by Rsdoctor GitHub Action

…ent tree-shaking

Add fallback for undefined moduleToHandlerMapping in shared container entry
Include additional plugins in filter list and prevent tree-shaking of shared modules by adding console logs when collectShared is true
Copy link
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 implements tree-shaking support for shared dependencies in Module Federation, allowing for more efficient bundle sizes by eliminating unused exports from shared modules. The implementation spans both Rust (core functionality) and JavaScript/TypeScript (API and runtime).

Changes:

  • Adds tree-shaking configuration options to shared dependencies with two modes: runtime-infer and server-calc
  • Implements plugins for collecting and optimizing shared module exports
  • Updates runtime to support dynamic loading of tree-shaken shared modules
  • Adds comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 84 out of 124 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
website/docs/{en,zh}/plugins/webpack/tree-shaking-shared-plugin.mdx New documentation for TreeShakingSharedPlugin
website/docs/{en,zh}/plugins/webpack/module-federation-plugin.mdx Documentation for new tree-shaking options
packages/rspack/src/sharing/*.ts TypeScript implementation of tree-shaking plugins
packages/rspack/src/container/*.ts Updates to Module Federation plugin
packages/rspack/src/runtime/moduleFederationDefaultRuntime.js Runtime support for tree-shaking
crates/rspack_plugin_mf/src/sharing/*.rs Rust implementation of tree-shaking logic
crates/rspack_plugin_mf/src/container/*.rs Container entry module changes
crates/rspack_core/src/*.rs Core type additions and dependency handling
tests/rspack-test/configCases/sharing/* Comprehensive test cases
pnpm-lock.yaml, package.json Dependency version updates
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

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

.into();
plugins.push(CollectSharedEntryPlugin::new(options).boxed())
}
BuiltinPluginName::SharedContainerPlugin => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is SharedContainerPlugin, can this merge into ContainerPlugin with an additional option?

Copy link
Member Author

Choose a reason for hiding this comment

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

While both plugins share the underlying ContainerEntryDependency , I don't think they should be merged or reused at the plugin level due to their distinct responsibilities and configurations:

  1. Different Responsibilities : ContainerPlugin is a general-purpose plugin for exposing multiple modules ( exposes ), whereas SharedContainerPlugin is specialized for wrapping a single shared dependency (like react ) into an isolated container, typically used with IndependentSharedPlugin .
  2. Configuration Structure : ContainerPlugin handles a complex list of exposes map and enhanced mode settings. SharedContainerPlugin focuses on a single request and version without the concept of exposes . Reusing ContainerPlugin here would require awkward parameter conversion (e.g., faking request as an exposes entry), which increases complexity.
  3. Runtime Behavior : They inject different RuntimeModule s ( ExposeRuntimeModule vs ShareContainerRuntimeModule ). Merging them would introduce unnecessary branching logic.
    I believe reusing them at the Dependency level (as they currently do) is the correct level of abstraction.

@hardfist hardfist merged commit cd402a1 into main Feb 5, 2026
47 of 49 checks passed
@hardfist hardfist deleted the feat/shared-treeshake branch February 5, 2026 05:14
hardfist added a commit that referenced this pull request Feb 5, 2026
Optimize the optimize_dependencies hook to reduce lock contention:
- Batch collect module info with single read lock instead of N times
- Batch apply mutations with single write lock instead of N times
- Pre-compute runtime referenced exports outside of write locks

This fixes performance regression introduced by #12250 where each
module iteration acquired separate read/write locks on module_graph.

Related: #12250
},
"peerDependencies": {
"@module-federation/runtime-tools": ">=0.22.0",
"@module-federation/runtime-tools": "0.24.1",
Copy link
Member

Choose a reason for hiding this comment

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

@2heal1 Why use a fixed version here? Should we include ^0.24.1 and ^2.0.0

'SharedUsedExportsOptimizerPlugin',
'HtmlWebpackPlugin',
'HtmlRspackPlugin',
'RsbuildHtmlPlugin',
Copy link
Member

Choose a reason for hiding this comment

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

Hardcoding an Rsbuild internal plugin name to @rspack/core doesn't seem like good practice...

This plugin class name isn't a public API and is unstable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.