Skip to content

feat: inline const for leaf modules #10451

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 15 commits into from
Jun 13, 2025
Merged

feat: inline const for leaf modules #10451

merged 15 commits into from
Jun 13, 2025

Conversation

ahabhgk
Copy link
Contributor

@ahabhgk ahabhgk commented May 22, 2025

Summary

Pre-PR for enum inlining

ref: evanw/esbuild@7bf3046

This PR only handle the cross-module part of const inlining, the idea is very similar to mangle exports:

  1. Add inlinable on export_info, which is similar to can_mangle, and add UsedName::Inlined for inlined value and UsedName::Normal for maybe mangled names
  2. Add inline_const parser plugin to find all the inlinable const variable, and "tag" it to tell the ESMExportSpecifierDependency that this exported value is inlinable

How to use:

{
  module: {
    rules: [{
      test: ...,
      parser: {
        inlineConst: false // use parser options to opt-out
      }
    }]
  },
  experiments: {
    inlineConst: true // enable the experimental switch
  }
}

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required update in future PR).

Copy link

netlify bot commented May 22, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3262cf1
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/684bbe6ba40c8b0008c87151

@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 May 22, 2025
Copy link

codspeed-hq bot commented May 22, 2025

CodSpeed Performance Report

Merging #10451 will not alter performance

Comparing const-inlining (3262cf1) with main (265fafe)

Summary

✅ 12 untouched benchmarks

@ahabhgk ahabhgk marked this pull request as ready for review May 27, 2025 07:48
@ahabhgk ahabhgk changed the title feat: inline "const" values that come first feat: inline const in leaf module May 27, 2025
@ahabhgk ahabhgk changed the title feat: inline const in leaf module feat: inline const for leaf modules May 27, 2025
@ahabhgk ahabhgk requested a review from JSerFeng May 27, 2025 08:21
@ahabhgk
Copy link
Contributor Author

ahabhgk commented May 27, 2025

CodSpeed regression is caused by extra get_used_name, will optimize the perf of get_used_name in future PR

@ahabhgk ahabhgk enabled auto-merge (squash) June 12, 2025 09:40
@ahabhgk ahabhgk merged commit 06b23af into main Jun 13, 2025
49 of 51 checks passed
@ahabhgk ahabhgk deleted the const-inlining branch June 13, 2025 06:38
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) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants