-
Notifications
You must be signed in to change notification settings - Fork 45.9k
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @GrinZero! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Comparing: 6d2a97a...5f7fb73 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
cc @sebmarkbage or anybody? I hope this PR can catch everyone's attention |
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:
And run
![image](https://private-user-images.githubusercontent.com/70185413/344745608-315cd0f2-683f-4807-89c9-ab58764ea1b3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1ODIzODIsIm5iZiI6MTcyMDU4MjA4MiwicGF0aCI6Ii83MDE4NTQxMy8zNDQ3NDU2MDgtMzE1Y2QwZjItNjgzZi00ODA3LTg5YzktYWI1ODc2NGVhMWIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEwVDAzMjgwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyMWI1NTYyZGE0ZjNkMjg1OWE5MDc5MTIxNjE5ZmEwYzJmYTVjY2YyMDI4MjRhZmY1YzU3MjNjYTM2ZjExZGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Yf7h_nYqr5Yn6J6DwiC-itxKqR_19l2mCuqxVD5nbLI)
build
ordev
: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