Skip to content
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

[compiler] use reactiveConditionHelper to reduce size #30171

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

GrinZero
Copy link

@GrinZero GrinZero commented Jul 1, 2024

I found that when studying react compiler, the compiler always compiles scope into very similar conditional comparison code blocks. So I am thinking about whether it is possible to extract these similar code blocks into a common function, which may help reduce the code volume of large-scale projects.

Overview

This PR introduces a new runtime, which I call conditionHelper. It organizes reusable logic in the scope and separates it into common functions to reduce the volume of compiled code. Although this is only an initial implementation and there are still testing and other tasks to be completed, it has a certain positive effect on reducing the volume of compiled code.

Demo

Modifying the babel option allows you to experience helpers, like:

...
  babel: {
    plugins: [
      [
        "babel-plugin-react-compiler",
        {
          environment: {
            enableReactiveScopeConditionHelper: true,
          },
        },
      ],
    ],
  },
...

And run build or dev:
image

TIP: This is my first time submitting a contribution to React. If anything that needs to be done is missing, please remind me and I will handle it as soon as possible

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ❌ Failed (Inspect) Jul 5, 2024 0:40am

@facebook-github-bot
Copy link

Hi @GrinZero!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@react-sizebot
Copy link

react-sizebot commented Jul 1, 2024

Comparing: 6d2a97a...5f7fb73

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 497.99 kB 497.99 kB = 89.27 kB 89.27 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 502.81 kB 502.81 kB = 89.97 kB 89.97 kB
facebook-www/ReactDOM-prod.classic.js = 597.08 kB 597.08 kB = 105.33 kB 105.33 kB
facebook-www/ReactDOM-prod.modern.js = 571.42 kB 571.42 kB = 101.27 kB 101.27 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against 5f7fb73

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@GrinZero GrinZero marked this pull request as draft July 2, 2024 01:29
@GrinZero
Copy link
Author

GrinZero commented Jul 2, 2024

cc @sebmarkbage or anybody? I hope this PR can catch everyone's attention

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

Successfully merging this pull request may close these issues.

None yet

3 participants