Skip to content

perf: improve flag exports plugin and flag usage plugin #10712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 27, 2025

Conversation

LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Jun 18, 2025

Summary

Impove FlagDependencyExportsPlugin

Parallel collecting exports of dependencies by dep.get_exports.

Since there is a backtracking mechanism in the processing of dependency exports, when re - exporting, if there is a relationship A -> B, after A is computed, when computing B, if B's exports change, then A's exports need to be recomputed.

If the computation queue is [B, A]:

  • For serial computation, first compute B's exports and immediately update the B's exports information to the module graph. So when A computes its exports, the module graph contains B's exports information.
  • For parallel computation, since A and B will compute their exports simultaneously on an empty module graph, and the subsequent update of A and B's exports to the module graph is sequential. As a result, the state of the module graph when A computes its exports will not match the state when it is updated. Also, because B is updated first and then A, the backtracking and recomputation of A cannot be triggered, leading to incorrect computation results.

If the computation queue is [A, B]:

  • For serial computation, first compute A's exports and immediately update the A's exports information to the module graph, but this information is useless. Because later B's exports will be computed and updated to the module graph, then triggering the recomputation of A. At this time, the module graph has B's exports information when A is computing.
  • For parallel computation, after A and B compute their exports and update them to the module graph, since B is updated after A, it will cause A to be recomputed. At this time, the module graph has B's exports information when A is computing, so the correct result can be obtained.

Therefore, modules need to be sorted according to their dependency relationships to ensure that the backtracking computation will be triggered, and the results of the first parallel computation are discarded. Although this will result in some wasted computations, since the number of re - exported modules is not particularly large, parallel computation will still significantly improve performance.

Improve FlagDependencyUsagePlugin

parallel collecting referenced exports of dependencies by dep.get_referenced_exports

This plugin has the same issue with FlagDependencyExportsPlugin. But it has a queue internal and has handle the dependencies by recursive calling collect_referenced_export_items. So it is safe to just parallel getting their referenced dependencies and no need to sort them.

Improve SideEffectsFlagPlugin

Just prevent CallExpr being cloned by sending the parent expr node to is_pure_call_expr function.

Related links

Checklist

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

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: refactor labels Jun 18, 2025
Copy link
Contributor Author

LingyuCoder commented Jun 18, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Base automatically changed from refactor/exports-info-getter-3 to main June 18, 2025 06:08
Copy link

netlify bot commented Jun 19, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 7ebe03c
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/685e0777b4c12b0008f24af8

@LingyuCoder LingyuCoder changed the title refactor: remove unnecessary self attributes of flag dependency exports state perf: parallel getting exports and referenced exports from dependencies Jun 19, 2025
@github-actions github-actions bot added release: performance release: performance related release(mr only) and removed release: refactor labels Jun 19, 2025
@LingyuCoder LingyuCoder force-pushed the refactor/flag-dep-exports-self branch from c6a51c0 to 4057c0d Compare June 19, 2025 04:36
@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 19, 2025
Copy link

codspeed-hq bot commented Jun 19, 2025

CodSpeed Performance Report

Merging #10712 will not alter performance

Comparing refactor/flag-dep-exports-self (7ebe03c) with main (ac04d4b)

Summary

✅ 16 untouched benchmarks

@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 19, 2025
@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 19, 2025
@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 19, 2025
@LingyuCoder LingyuCoder force-pushed the refactor/flag-dep-exports-self branch from af96732 to 7c5f196 Compare June 19, 2025 09:47
@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 19, 2025
@LingyuCoder LingyuCoder force-pushed the refactor/flag-dep-exports-self branch from e8a6cbc to 181c7af Compare June 20, 2025 03:01
@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 20, 2025
Copy link
Contributor

github-actions bot commented Jun 20, 2025

📝 Benchmark detail: Open

Name Base (2025-06-20 ff654c6) Current Change
10000_big_production-mode_disable-minimize + exec 35.2 s ± 522 ms 35.9 s ± 619 ms +1.85 %
10000_development-mode + exec 1.96 s ± 45 ms 1.89 s ± 24 ms -3.37 %
10000_development-mode_hmr + exec 704 ms ± 23 ms 716 ms ± 36 ms +1.57 %
10000_production-mode + exec 2.4 s ± 30 ms 2.22 s ± 48 ms -7.11 %
10000_production-mode_persistent-cold + exec 2.54 s ± 61 ms 2.37 s ± 49 ms -6.57 %
10000_production-mode_persistent-hot + exec 1.82 s ± 63 ms 1.74 s ± 22 ms -4.51 %
arco-pro_development-mode + exec 1.81 s ± 30 ms 1.85 s ± 121 ms +2.27 %
arco-pro_development-mode_hmr + exec 371 ms ± 2.6 ms 372 ms ± 1.3 ms +0.10 %
arco-pro_production-mode + exec 3.43 s ± 77 ms 3.39 s ± 183 ms -1.07 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.53 s ± 98 ms 3.47 s ± 107 ms -1.71 %
arco-pro_production-mode_persistent-cold + exec 3.53 s ± 70 ms 3.51 s ± 203 ms -0.33 %
arco-pro_production-mode_persistent-hot + exec 2.18 s ± 71 ms 2.15 s ± 26 ms -1.61 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.51 s ± 237 ms 3.41 s ± 80 ms -2.91 %
large-dyn-imports_development-mode + exec 2.17 s ± 11 ms 2.15 s ± 64 ms -1.15 %
large-dyn-imports_production-mode + exec 2.17 s ± 43 ms 2.09 s ± 16 ms -3.75 %
threejs_development-mode_10x + exec 1.52 s ± 156 ms 1.47 s ± 8.4 ms -3.63 %
threejs_development-mode_10x_hmr + exec 844 ms ± 22 ms 849 ms ± 18 ms +0.56 %
threejs_production-mode_10x + exec 4.95 s ± 29 ms 4.97 s ± 316 ms +0.23 %
threejs_production-mode_10x_persistent-cold + exec 5.15 s ± 217 ms 5.03 s ± 185 ms -2.22 %
threejs_production-mode_10x_persistent-hot + exec 4.47 s ± 126 ms 4.45 s ± 171 ms -0.43 %
10000_big_production-mode_disable-minimize + rss memory 9169 MiB ± 153 MiB 9365 MiB ± 64.7 MiB +2.14 %
10000_development-mode + rss memory 675 MiB ± 29 MiB 704 MiB ± 24 MiB +4.27 %
10000_development-mode_hmr + rss memory 803 MiB ± 13.7 MiB 826 MiB ± 9.66 MiB +2.84 %
10000_production-mode + rss memory 658 MiB ± 30.6 MiB 696 MiB ± 64.7 MiB +5.83 %
10000_production-mode_persistent-cold + rss memory 763 MiB ± 27.8 MiB 798 MiB ± 22.1 MiB +4.61 %
10000_production-mode_persistent-hot + rss memory 756 MiB ± 18.2 MiB 739 MiB ± 65.5 MiB -2.28 %
arco-pro_development-mode + rss memory 609 MiB ± 61 MiB 609 MiB ± 55.4 MiB +0.12 %
arco-pro_development-mode_hmr + rss memory 491 MiB ± 10.6 MiB 532 MiB ± 13.4 MiB +8.46 %
arco-pro_production-mode + rss memory 678 MiB ± 57.4 MiB 699 MiB ± 118 MiB +3.04 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 688 MiB ± 76.4 MiB 737 MiB ± 34.5 MiB +7.08 %
arco-pro_production-mode_persistent-cold + rss memory 807 MiB ± 58.6 MiB 812 MiB ± 131 MiB +0.59 %
arco-pro_production-mode_persistent-hot + rss memory 658 MiB ± 107 MiB 658 MiB ± 47.1 MiB -0.01 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 675 MiB ± 97.8 MiB 704 MiB ± 75.9 MiB +4.23 %
large-dyn-imports_development-mode + rss memory 683 MiB ± 4.67 MiB 708 MiB ± 13 MiB +3.60 %
large-dyn-imports_production-mode + rss memory 560 MiB ± 6.84 MiB 574 MiB ± 3.49 MiB +2.40 %
threejs_development-mode_10x + rss memory 602 MiB ± 7.55 MiB 625 MiB ± 11.2 MiB +3.86 %
threejs_development-mode_10x_hmr + rss memory 772 MiB ± 29.1 MiB 849 MiB ± 50.6 MiB +9.94 %
threejs_production-mode_10x + rss memory 857 MiB ± 34.6 MiB 874 MiB ± 11.1 MiB +1.99 %
threejs_production-mode_10x_persistent-cold + rss memory 946 MiB ± 66 MiB 956 MiB ± 32.3 MiB +0.98 %
threejs_production-mode_10x_persistent-hot + rss memory 804 MiB ± 28.4 MiB 819 MiB ± 39.3 MiB +1.89 %

Copy link
Contributor

github-actions bot commented Jun 20, 2025

📝 Ecosystem CI detail: Open

suite result
rslib ✅ success
rspress ✅ success
rsdoctor ❌ failure
devserver ❌ failure
rsbuild ✅ success
examples ❌ failure
modernjs ❌ failure
nuxt ✅ success
lynx-stack ✅ success
plugin ✅ success

@LingyuCoder LingyuCoder marked this pull request as ready for review June 23, 2025 03:07
@LingyuCoder LingyuCoder changed the title perf: parallel getting exports and referenced exports from dependencies perf: improve flag exports plugin and flag usage plugin Jun 26, 2025
@LingyuCoder LingyuCoder force-pushed the refactor/flag-dep-exports-self branch from 181c7af to 56fa1c5 Compare June 26, 2025 11:04
Copy link
Contributor

github-actions bot commented Jun 26, 2025

📝 Benchmark detail: Open

Name Base (2025-06-26 006d33e) Current Change
10000_big_production-mode_disable-minimize + exec 34.2 s ± 681 ms 34.8 s ± 350 ms +1.69 %
10000_development-mode + exec 1.89 s ± 25 ms 1.88 s ± 51 ms -0.54 %
10000_development-mode_hmr + exec 706 ms ± 20 ms 690 ms ± 23 ms -2.29 %
10000_production-mode + exec 2.23 s ± 42 ms 2 s ± 198 ms -10.14 %
10000_production-mode_persistent-cold + exec 2.41 s ± 139 ms 2.11 s ± 34 ms -12.47 %
10000_production-mode_persistent-hot + exec 1.72 s ± 37 ms 1.53 s ± 43 ms -10.77 %
arco-pro_development-mode + exec 1.83 s ± 55 ms 1.8 s ± 101 ms -1.40 %
arco-pro_development-mode_hmr + exec 371 ms ± 2.2 ms 373 ms ± 1.5 ms +0.44 %
arco-pro_production-mode + exec 3.77 s ± 77 ms 3.33 s ± 108 ms -11.65 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.81 s ± 356 ms 3.45 s ± 252 ms -9.41 %
arco-pro_production-mode_persistent-cold + exec 3.92 s ± 278 ms 3.42 s ± 153 ms -12.83 %
arco-pro_production-mode_persistent-hot + exec 2.17 s ± 65 ms 2.11 s ± 56 ms -2.52 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.77 s ± 443 ms 3.4 s ± 99 ms -9.86 %
large-dyn-imports_development-mode + exec 2.12 s ± 37 ms 2.15 s ± 62 ms +1.37 %
large-dyn-imports_production-mode + exec 2.18 s ± 36 ms 2.15 s ± 62 ms -1.75 %
threejs_development-mode_10x + exec 1.45 s ± 39 ms 1.49 s ± 153 ms +2.58 %
threejs_development-mode_10x_hmr + exec 834 ms ± 22 ms 840 ms ± 7.8 ms +0.72 %
threejs_production-mode_10x + exec 4.78 s ± 70 ms 4.71 s ± 60 ms -1.54 %
threejs_production-mode_10x_persistent-cold + exec 4.92 s ± 25 ms 4.87 s ± 74 ms -0.99 %
threejs_production-mode_10x_persistent-hot + exec 4.35 s ± 32 ms 4.36 s ± 298 ms +0.23 %
10000_big_production-mode_disable-minimize + rss memory 9256 MiB ± 171 MiB 9436 MiB ± 200 MiB +1.94 %
10000_development-mode + rss memory 674 MiB ± 18 MiB 705 MiB ± 26.2 MiB +4.61 %
10000_development-mode_hmr + rss memory 822 MiB ± 39.6 MiB 845 MiB ± 43 MiB +2.70 %
10000_production-mode + rss memory 651 MiB ± 32.8 MiB 704 MiB ± 59.5 MiB +8.20 %
10000_production-mode_persistent-cold + rss memory 769 MiB ± 24.2 MiB 806 MiB ± 44.3 MiB +4.84 %
10000_production-mode_persistent-hot + rss memory 776 MiB ± 45.3 MiB 786 MiB ± 32.8 MiB +1.23 %
arco-pro_development-mode + rss memory 591 MiB ± 26 MiB 606 MiB ± 40.5 MiB +2.60 %
arco-pro_development-mode_hmr + rss memory 501 MiB ± 17.3 MiB 515 MiB ± 12.8 MiB +2.65 %
arco-pro_production-mode + rss memory 678 MiB ± 69.6 MiB 691 MiB ± 58.9 MiB +1.99 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 694 MiB ± 24.3 MiB 678 MiB ± 50.3 MiB -2.34 %
arco-pro_production-mode_persistent-cold + rss memory 752 MiB ± 52.4 MiB 786 MiB ± 123 MiB +4.57 %
arco-pro_production-mode_persistent-hot + rss memory 685 MiB ± 69.6 MiB 682 MiB ± 76.9 MiB -0.43 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 674 MiB ± 29.2 MiB 707 MiB ± 45 MiB +4.97 %
large-dyn-imports_development-mode + rss memory 695 MiB ± 3.53 MiB 715 MiB ± 19 MiB +2.87 %
large-dyn-imports_production-mode + rss memory 576 MiB ± 8.68 MiB 586 MiB ± 9.66 MiB +1.79 %
threejs_development-mode_10x + rss memory 613 MiB ± 13.9 MiB 632 MiB ± 16.6 MiB +2.97 %
threejs_development-mode_10x_hmr + rss memory 788 MiB ± 35.8 MiB 840 MiB ± 37.9 MiB +6.61 %
threejs_production-mode_10x + rss memory 864 MiB ± 50.9 MiB 881 MiB ± 145 MiB +2.00 %
threejs_production-mode_10x_persistent-cold + rss memory 958 MiB ± 29.6 MiB 947 MiB ± 40.6 MiB -1.16 %
threejs_production-mode_10x_persistent-hot + rss memory 832 MiB ± 45.5 MiB 827 MiB ± 21.9 MiB -0.61 %

@web-infra-dev web-infra-dev deleted a comment from github-actions bot Jun 26, 2025
Copy link
Contributor

github-actions bot commented Jun 26, 2025

📝 Ecosystem CI detail: Open

suite result
rspress ✅ success
devserver ❌ failure
modernjs ❌ failure
nuxt ✅ success
plugin ❌ failure
rsbuild ❌ failure
rsdoctor ❌ failure
rslib ✅ success
examples ✅ success
lynx-stack ✅ success

@LingyuCoder LingyuCoder force-pushed the refactor/flag-dep-exports-self branch from 56fa1c5 to 7ebe03c Compare June 27, 2025 02:52
@@ -1479,6 +1479,7 @@ impl Compilation {
#[instrument("Compilation:seal", skip_all)]
pub async fn seal(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> {
self.other_module_graph = Some(ModuleGraphPartial::default());
self.get_module_graph_mut().prepare_export_info_map();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause all exports info will get_mut during flag exports and usage, so we can just clone the whole map to module graph partial to prevent loop partials of each export info. This should be removed after refactoring of export info.

@LingyuCoder LingyuCoder requested review from JSerFeng and ahabhgk June 27, 2025 05:31
@JSerFeng
Copy link
Contributor

LGTM cc @ahabhgk

Copy link
Contributor

@ahabhgk ahabhgk left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ahabhgk ahabhgk enabled auto-merge (squash) June 27, 2025 05:44
@ahabhgk ahabhgk merged commit 75e843a into main Jun 27, 2025
42 checks passed
@ahabhgk ahabhgk deleted the refactor/flag-dep-exports-self branch June 27, 2025 05:44
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.

3 participants