-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Ensure function arity is preserved after build #31808
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Great find!
message: | ||
'Google Closure Compiler optimized `arguments` access. ' + | ||
'This affects function arity. ' + | ||
'Access `arguments.length` to avoid this optimization', |
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.
We should update this. This advise does not work
Comparing: 34ee391...f229077 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
Closes #31578
Closes #31598
Problem
The google closure compiler has a feature for optimizing function calls. It identifies opportunities to replace the original argument arrays with a more compact representation, such as array or replace constant arguments with their literal values.
In the case of functions that use
arguments
it added an extra parameter and caused the arity (fn.length) to differ (which became different from development to prod due to DEV).This became an issue for reason-react (and maybe other binding systems as well), since we need to bind to the interface and statically how many parameters are expected. reason-react carries the OCaml-way of being a curried language where there's no difference between
let fn = (a, b) => ...
andlet fn = (a) => (b) => ...
. The compiler to JavaScript (Melange) has a small runtime that calls the function with the right number of parameters. This is the related issue: reasonml/reason-react#860.Solution
At first, I made it work with the
// @nocollapse
annotation (https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nocollapse), but I found out that just adding a reference is more clear on the intention of the gcc to not optimze this bit, rather than using a no-obvious annotation that seems to do the job.Thanks @eps1lon for the help