Skip to content

refactor: render runtime globals by runtime template#12272

Merged
LingyuCoder merged 3 commits intomainfrom
refactor/render-template-ident
Nov 25, 2025
Merged

refactor: render runtime globals by runtime template#12272
LingyuCoder merged 3 commits intomainfrom
refactor/render-template-ident

Conversation

@LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Nov 24, 2025

Summary

This refactoring is aimed at smoothly replacing __webpack_require__ in the bundled assets with __rspack_require__ or some else in the future.

In the runtime template, runtime globals are rendered according to the compiler options, and its fmt trait and name() method are removed.

However, since some parsers also use runtime globals for for_name matching, the runtime template without the dojang template engine is added to the TaskContext and sent to parser.

Related links

Checklist

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

@netlify
Copy link

netlify bot commented Nov 24, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit bbc3ad7
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6924424dd5777b0008424404

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

github-actions bot commented Nov 24, 2025

📦 Binary Size-limit

Comparing bbc3ad7 to feat: support SRI with experiments.css and CssExtractRspackPlugin (#12239) by harpsealjs

❌ Size increased by 23.00KB from 47.63MB to 47.65MB (⬆️0.05%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 24, 2025

CodSpeed Performance Report

Merging #12272 will not alter performance

Comparing refactor/render-template-ident (bbc3ad7) with main (e23badc)

Summary

✅ 17 untouched

@github-actions
Copy link
Contributor

⏳ Triggered benchmark: Open

@LingyuCoder LingyuCoder force-pushed the refactor/render-template-ident branch from 12c83f9 to bbc3ad7 Compare November 24, 2025 11:32
@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

📝 Benchmark detail: Open

Name Base (2025-11-24 e23badc) Current Change
10000_big_production-mode_disable-minimize + exec 24.7 s ± 172 ms 25 s ± 569 ms +1.16 %
10000_development-mode + exec 1.29 s ± 13 ms 1.27 s ± 20 ms -1.61 %
10000_development-mode_hmr + exec 627 ms ± 4.4 ms 598 ms ± 8.9 ms -4.66 %
10000_development-mode_noop-loader + exec 2.23 s ± 85 ms 2.22 s ± 34 ms -0.66 %
10000_production-mode + exec 1.35 s ± 13 ms 1.34 s ± 80 ms -0.68 %
10000_production-mode_persistent-cold + exec 1.48 s ± 24 ms 1.45 s ± 23 ms -1.96 %
10000_production-mode_persistent-hot + exec 1.04 s ± 26 ms 1.01 s ± 12 ms -3.10 %
arco-pro_development-mode + exec 1.58 s ± 90 ms 1.6 s ± 53 ms +1.40 %
arco-pro_development-mode_hmr + exec 358 ms ± 1.8 ms 358 ms ± 1.1 ms -0.04 %
arco-pro_production-mode + exec 2.85 s ± 58 ms 2.81 s ± 66 ms -1.74 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.93 s ± 92 ms 2.91 s ± 64 ms -0.66 %
arco-pro_production-mode_persistent-cold + exec 2.97 s ± 135 ms 2.92 s ± 131 ms -1.73 %
arco-pro_production-mode_persistent-hot + exec 1.64 s ± 46 ms 1.65 s ± 70 ms +0.59 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.84 s ± 99 ms 2.9 s ± 192 ms +2.21 %
large-dyn-imports_development-mode + exec 1.58 s ± 37 ms 1.56 s ± 21 ms -1.54 %
large-dyn-imports_production-mode + exec 1.62 s ± 72 ms 1.61 s ± 88 ms -0.58 %
threejs_development-mode_10x + exec 1.27 s ± 19 ms 1.27 s ± 53 ms -0.03 %
threejs_development-mode_10x_hmr + exec 889 ms ± 8.1 ms 900 ms ± 25 ms +1.29 %
threejs_production-mode_10x + exec 3.88 s ± 45 ms 3.91 s ± 244 ms +0.78 %
threejs_production-mode_10x_persistent-cold + exec 4.01 s ± 28 ms 3.99 s ± 27 ms -0.34 %
threejs_production-mode_10x_persistent-hot + exec 3.5 s ± 77 ms 3.49 s ± 142 ms -0.42 %
10000_big_production-mode_disable-minimize + rss memory 5352 MiB ± 189 MiB 5328 MiB ± 90.7 MiB -0.44 %
10000_development-mode + rss memory 587 MiB ± 23.1 MiB 572 MiB ± 40.6 MiB -2.56 %
10000_development-mode_hmr + rss memory 743 MiB ± 12.7 MiB 731 MiB ± 20.9 MiB -1.55 %
10000_development-mode_noop-loader + rss memory 881 MiB ± 35.9 MiB 875 MiB ± 18 MiB -0.64 %
10000_production-mode + rss memory 608 MiB ± 31.9 MiB 598 MiB ± 18.8 MiB -1.72 %
10000_production-mode_persistent-cold + rss memory 685 MiB ± 28.5 MiB 670 MiB ± 23.1 MiB -2.18 %
10000_production-mode_persistent-hot + rss memory 679 MiB ± 31.8 MiB 646 MiB ± 66.1 MiB -4.83 %
arco-pro_development-mode + rss memory 463 MiB ± 31.4 MiB 471 MiB ± 20 MiB +1.73 %
arco-pro_development-mode_hmr + rss memory 383 MiB ± 11.9 MiB 386 MiB ± 12.1 MiB +0.57 %
arco-pro_production-mode + rss memory 562 MiB ± 15.5 MiB 584 MiB ± 56.7 MiB +3.96 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 577 MiB ± 40 MiB 597 MiB ± 71.9 MiB +3.53 %
arco-pro_production-mode_persistent-cold + rss memory 667 MiB ± 48.2 MiB 672 MiB ± 34.5 MiB +0.76 %
arco-pro_production-mode_persistent-hot + rss memory 499 MiB ± 56.5 MiB 519 MiB ± 86 MiB +4.02 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 561 MiB ± 54.3 MiB 583 MiB ± 72.2 MiB +4.02 %
large-dyn-imports_development-mode + rss memory 605 MiB ± 1.36 MiB 604 MiB ± 6.62 MiB -0.04 %
large-dyn-imports_production-mode + rss memory 543 MiB ± 6.8 MiB 542 MiB ± 12.1 MiB -0.05 %
threejs_development-mode_10x + rss memory 540 MiB ± 15.5 MiB 533 MiB ± 28.1 MiB -1.22 %
threejs_development-mode_10x_hmr + rss memory 764 MiB ± 65 MiB 751 MiB ± 62.9 MiB -1.74 %
threejs_production-mode_10x + rss memory 640 MiB ± 104 MiB 662 MiB ± 97.1 MiB +3.37 %
threejs_production-mode_10x_persistent-cold + rss memory 756 MiB ± 60.6 MiB 745 MiB ± 31.7 MiB -1.40 %
threejs_production-mode_10x_persistent-hot + rss memory 583 MiB ± 44.6 MiB 587 MiB ± 29.8 MiB +0.75 %

@LingyuCoder LingyuCoder marked this pull request as ready for review November 25, 2025 04:26
@LingyuCoder LingyuCoder requested a review from ahabhgk as a code owner November 25, 2025 04:26
Copilot AI review requested due to automatic review settings November 25, 2025 04:26
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 refactoring introduces a centralized way to render runtime globals through the RuntimeTemplate, replacing direct .name() and .to_string() calls on RuntimeGlobals. This enables future customization of the runtime scope name (e.g., replacing __webpack_require__ with __rspack_require__).

Key changes:

  • Removed Display trait and .name() method from RuntimeGlobals
  • Created runtime_globals_to_string() function that uses CompilerOptions for rendering
  • Added render_runtime_globals() method to RuntimeTemplate
  • Threaded RuntimeTemplate through parsers via TaskContext and ParseContext

Reviewed changes

Copilot reviewed 87 out of 87 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rspack_core/src/runtime_globals.rs Removed Display impl and .name() method, added runtime_globals_to_string() function
crates/rspack_core/src/runtime_template.rs Refactored to accept CompilerOptions, added render_runtime_globals() method, made dojang optional via clone_without_dojang()
crates/rspack_core/src/parser_and_generator.rs Added runtime_template field to ParseContext
crates/rspack_core/src/module.rs Added runtime_template field to BuildContext
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs Added runtime_template field to JavascriptParser
crates/rspack_plugin_javascript/src/parser_plugin/*.rs Updated all parser plugins to use parser.runtime_template.render_runtime_globals()
crates/rspack_plugin_javascript/src/dependency/**/*.rs Updated dependency templates to use compilation.runtime_template.render_runtime_globals()
crates/rspack_plugin_runtime/src/**/*.rs Updated runtime modules to use compilation.runtime_template.render_runtime_globals()
All other plugin files Consistently replaced runtime global rendering with the new API
Comments suppressed due to low confidence (2)

crates/rspack_plugin_javascript/src/plugin/mod.rs:1

  • [nitpick] The formatting pattern for render_runtime_globals() calls is inconsistent. In some places, it's on a single line within a string interpolation, while in others (like line 491), it's assigned to a variable or called directly. For maintainability, consider establishing a consistent pattern, especially when the result is used multiple times in the same expression.
    crates/rspack_core/src/runtime_template.rs:1
  • This TODO comment is critical to the purpose of this refactoring. It should be expanded to clarify what configuration option will be used, or better yet, create a tracking issue and reference it here (e.g., 'TODO(#1234): use compiler_options.output.runtime_scope_name').
use std::{

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

@LingyuCoder LingyuCoder merged commit cb2a294 into main Nov 25, 2025
55 checks passed
@LingyuCoder LingyuCoder deleted the refactor/render-template-ident branch November 25, 2025 04:46
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