Skip to content

Migrate webchannel-wrapper to gulp + google-closure-compiler #2891

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

Merged
merged 19 commits into from
May 1, 2020
Merged

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Apr 9, 2020

Webchannel wrapper was previously using closure-builder which bundles its specific version of closure-library and is not updated often. This led to a bug where it was configured to be compiling to an ES5 target but ignored that option (language_out) and compiled to ES2017. This could cause a bug in IE if the app is using untransformed code directly from webchannel-wrapper/dist, such as in rxfire tests run in IE.

Moving to use gulp which directly uses google-closure-compiler and correctly recognizes the language_out attribute.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 9, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (16938c0) Head (55f6e8d) Diff
    browser 248 kB 247 kB -1.27 kB (-0.5%)
    esm2017 194 kB 193 kB -1.26 kB (-0.6%)
    main 489 kB 487 kB -1.46 kB (-0.3%)
    module 246 kB 245 kB -1.32 kB (-0.5%)
  • @firebase/firestore/memory

    Type Base (16938c0) Head (55f6e8d) Diff
    browser 189 kB 188 kB -1.28 kB (-0.7%)
    esm2017 149 kB 148 kB -1.27 kB (-0.9%)
    main 366 kB 364 kB -1.45 kB (-0.4%)
    module 188 kB 186 kB -1.34 kB (-0.7%)
  • @firebase/webchannel-wrapper

    Type Base (16938c0) Head (55f6e8d) Diff
    esm2017 ? 37.7 kB ? (?)
    main 40.4 kB 38.8 kB -1.60 kB (-3.9%)
    module 41.2 kB 38.4 kB -2.82 kB (-6.8%)
  • firebase

    Type Base (16938c0) Head (55f6e8d) Diff
    firebase-firestore.js 290 kB 286 kB -4.30 kB (-1.5%)
    firebase-firestore.memory.js 232 kB 228 kB -4.31 kB (-1.9%)
    firebase.js 824 kB 819 kB -4.34 kB (-0.5%)

Test Logs

resolve(__dirname, './externs/overrides.js'),
resolve(__dirname, './externs/module.js')
],
language_out: 'ES5',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be an option? I wonder if we would get size savings if we used ES2017 for our ES2017 build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an ES2017 build, size comparison:

47365 packages/webchannel-wrapper/dist/index.esm.js
41267 packages/webchannel-wrapper/dist/index.esm2017.js
47021 packages/webchannel-wrapper/dist/index.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think that is worth the effort. Do you know why the SDK size went up, despite this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that previously all builds were actually ES2017, due to a bug in closure-builder. This was great for size but not great for ES5 compatibility. Now the builds that are supposed to be ES5 actually are (making them bigger) and a correctly-labeled ES2017 build has been added.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought more about this - the size increase for the NPM builds are explained by these changes. The size increase for the CDN build is not though. The CDN build should have post processed everything to ES5 already. Hence, I think what is going on here is that the new build pipeline is no longer tree shaking code that Firestore isn’t using. Is that a possibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my explanation is incorrect for the ESM bundle which was already writing ES5, I think because of using an outdated library (see below). The bundle size increase is actually due to a change in closure-library from versions 20200112 to 20200204. I don't know exactly which change yet, but this led to a 5K bundle size spike on the webchannel-wrapper ES5 builds between those two closure-library versions.

Because webchannel-wrapper was using closure-builder, the ESM build was fixed on a pretty old version bundled with closure-builder. Once we upgraded it to use a newer version of google-closure-library (20200224, I copied the version auth was using) it saw a 5K size increase.

If we upgrade to the latest version of google-closure-library (20200406) the size increase is smaller (2.5K) but still there.

For now we might want to pin closure-library to 20200112 (before the change that caused this size increase) and try to figure out exactly where the increase is coming from.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM to me (but I mostly just compared the previous to the new settings). Please wait for @Feiyang1 to review and consider adding ES2017 builds if this cuts down on bundle size in a significant way,

@hsubox76
Copy link
Contributor Author

Pinning to closure-library and closure-compiler versions 20200112. Recent closure-library versions starting at 0204 increase the bundle size, although the most recent version (0406) has a smaller size increase. Latest closure-compiler doesn't cause problems but better to keep versions in sync?

Unfortunately the esm2017 build using 0112 doesn't seem to be much of a size savings, but it does decrease by 3K with 0406 so seems like it's worth keeping in there for potential size savings when we're able to upgrade closure-library.

@hsubox76
Copy link
Contributor Author

Upgraded to latest closure deps. Using closure to compile to ES2017, then Typescript to compile to ES5. Final bundle sizes should be smaller now. "ES5" bundles do include Set but we already require developers to include their own polyfills, and Saucelabs tests will include polyfills as well.

Ideally auth should upgrade closure versions as well, but this currently causes auth tests to fail and would require more investigation.

typescriptPlugin({
typescript,
// Uncomment for development only. Prevents caching between builds.
// clean: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed? I thought it is only necessary if we are doing custom source code transformation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Typescript needed or is clean needed? Lack of clean seems to cause problems when trying different Typescript config options during development and it seems good to remind myself/others to use it next time we try to tweak the config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean. Should we always enable it then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed if you're not changing the Typescript config, and caching saves time.

Copy link
Member

@Feiyang1 Feiyang1 Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should I enable it, I don't think we are changing the config? Sorry that I'm nitpicking. If it is not really needed, I think we should just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to leave a note for anyone in the future who has to tinker with the build pipeline so they don't forget to enable this when working, or they will get really frustrated when changes to tsconfig don't seem to do anything. But I don't want to leave it on for production and regular usage. I don't know if a comment is the best place to leave that note, but if it's outside the code I don't think anyone will remember to check.

@hsubox76 hsubox76 merged commit ba5a37c into master May 1, 2020
@firebase firebase locked and limited conversation to collaborators Jun 1, 2020
@hsubox76 hsubox76 deleted the ch-gulp branch June 18, 2020 21:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants