Add parentheses to factory function of UMD bundles to avoid lazy parsing #3183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
Most modern javascript engines use lazy parsing technique to boost startup performance, which means function will not be fully parsed until it is executed. For IIFE or soon-be-called callback function, we should use parentheses to wrap it to avoid double parsing(lazy parsing + full parsing).
Tested using the previous benchmark https://bl.ocks.org/nolanlawson/raw/b6d57ef2b2ac8147bc6fd300b8183566, unwrapped bundles are a lot slower to load. You can also use this gist https://gist.github.com/ajihyf/d147454691f6d477ba36dac64c13c531 to test locally using node.The benchmarks above are all wrong. We should use
eval
. Example gist: https://gist.github.com/ajihyf/d1a38e2791d25f702f7c363a1813d563There was already #774 to solve this issue. However, the latest Rollup lost this functionality. This PR just adds parentheses back and some comments to prevent regression.