-
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 cla@meta.com. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. We're not opposed to exploring changes to the output format, but:
a) We want to find one format that is the best combination of code size and runtime performance, not have long-lived feature flags for people to choose.
b) If we use higher-level helpers, the cost of those has to be carefully tested to ensure they don't regress other properties.
In this case, I'm concerned that this reintroduces lots of array and closure allocations in exchange for reduced code size. So far we've been mostly memory neutral, but this could easily make the compiled output use more memory than before.
If you finish implementing this such that CI is green, we can try benchmarking it. But we'd only be move forward if the results are positive.
const test = | ||
conditionTargets === null | ||
? (i: number) => cache[conditionIndexs[i]] === $empty | ||
: (i: number) => cache[conditionIndexs[i]] !== conditionTargets[i]; | ||
const condition = (() => { | ||
for (let i = 0; i < conditionIndexs.length; i++) { | ||
if (test(i)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really inefficient. Let's turn this into static code without the unnecessary closure allocations. ie
let hasChange = false;
for (let i = 0; i < conditionIndices.length; i++) {
...
if (cache[conditionIndices[i]] !== conditionTargets[i]) {
hasChange = true;
break;
}
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requesting changes to get this to pass CI before we can proceed with anything
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
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