-
Notifications
You must be signed in to change notification settings - Fork 930
Pre-process all ES5 builds #2840
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
Conversation
Binary Size ReportAffected SDKs
Test Logs |
d01322f
to
0027ac1
Compare
LGTM. I'm glad (surprised?) to see that it reduces the memory only build significantly. It's also interesting to see that the size of |
Validation checklist: [x] Browser builds are mangled |
@Feiyang1 This should now be ready for an actual review. I manually tested all builds. |
@@ -45,6 +48,10 @@ import { | |||
// The in-memory builds are roughly 130 KB smaller, but throw an exception | |||
// for calls to `enablePersistence()` or `clearPersistence()`. | |||
// | |||
// We use two different rollup pipelines to take advantage of tree shaking in |
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.
Probably mention that it's because rollup is not able to treeshake Typescript classes compiled to ES5.
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.
Done
}, | ||
include: ['dist/*.js'] | ||
}), | ||
terser({ |
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.
Do we need terser again here since we already do it with the same options (comments: all, beautify: true) when producing esm2017 builds?
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.
I believe the size went up without Terser here, but I will do another round to verify.
Update: The size without Terser is about 4% larger (which I don't quite understand either, since we Terser again before computing the size). I added it back.
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.
IIUC, we are not doing property mangling here, and we don't care about the size saving by mangling variable names. Developers will do them when building their apps.
Removing terser here can save some build time.
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.
Ok, removed.
import memoryPkg from './memory/package.json'; | ||
|
||
// This file defines the second rollup pipeline and transpiles the ES2017 SDK | ||
// into ES3 code. By splitting the build process into two independent build |
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.
I think it should be ES5 code.
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.
I forgot to look in base configuration and assumed we used the default, which is ES3. Fixed.
typescript, | ||
compilerOptions: { | ||
allowJs: true, | ||
importHelpers: true |
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.
It can be removed because It's already set in the root tsconfig.
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 didn't work for me when it was not included yesterday, but I will try again. Fingers crossed :)
Update: No size impact so I removed it.
packages/firestore/package.json
Outdated
@@ -26,6 +26,7 @@ | |||
"prepare": "yarn build" | |||
}, | |||
"main": "dist/index.node.cjs.js", | |||
"mainES2017": "dist/index.node.esm2017.js", |
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.
main-esm2017
to be consistent with the existing convention? We have a lite-esm2017
target in @firebase/app which is used to produce firebase-performance-standalone.es2017.js
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.
I was looking for a precedent. I am glad there is one :)
@@ -2,6 +2,7 @@ | |||
"name": "@firebase/firestore/memory", | |||
"description": "A memory-only build of the Cloud Firestore JS SDK.", | |||
"main": "../dist/index.memory.node.cjs.js", | |||
"mainES2017": "../dist/index.memory.node.esm2017.js", |
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.
main-esm2017
?
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.
Done
3da5216
to
2b6a594
Compare
2b6a594
to
3a26d5e
Compare
@@ -45,6 +48,11 @@ import { | |||
// The in-memory builds are roughly 130 KB smaller, but throw an exception | |||
// for calls to `enablePersistence()` or `clearPersistence()`. | |||
// | |||
// We use two different rollup pipelines to take advantage of tree shaking, | |||
// which Rollup only supports in pure ES2017 builds. The build pipeline in this |
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 not accurate. rollup can tree shake ES5 builds as long as they are in the ESM format. The limitation is specific to the Typescript classes compiled down to ES5.
Also do you mean post-tree shaken ES2017
builds? IIUC, treeshaking is done in this phase, the second phase just changes the module format.
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.
Updated the comment. I did mean "pre tree-shaken", as in "these builds are already tree shaken", which is the same as "post tree-shaken". Hence, I dropped the term.
I also updated the PR to remove the error handling for memory externs, which was meant to ensure that our ES5 builds don't accidentally pull in sources they don't need. If this happens now, Rollup will just tree shake those files. |
@Feiyang1 I have to test these builds but this might enable tree-shaking in ES3/5 builds. I got this to work by using two different rollup phases.