Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Bundle reductions inspired by examples/rollup app. #2842

Merged
merged 3 commits into from
Mar 5, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Mar 5, 2019

Part of our ongoing effort to rein in bundle sizes: #2743

Although the bundlesize check will show a reduction in the size of react-apollo itself, the most accurate measurement of these improvements is the examples/rollup app, introduced by #2839.

That said, the numbers are pretty close, because the tslib package is now shared by so many Apollo packages that it's effectively free from the perspective of any single package.

Undefined values were not necessarily a problem in this code, so the
compact helper was probably not strictly necessary to begin with, but the
most likely cause of undefined values was the unnecessary destructuring of
props, and the enumeration of all properties when creating the new object.
Object spread syntax is a better tool for this job.

Perhaps more importantly, by eliminating the compact helper function,
whose return type was any, we exposed some typing problems with the
extractOptsFromProps method, which I have also fixed.
Similar in spirit to apollographql/apollo-link#959

This inlining was first introduced in PR #2661 with the following commit:
de2b5fc

At the time, inlining made sense because TypeScript was injecting copies
of the __extends, __rest, etc. helpers into every module that used them.
Depending on the tslib package seemed undesirable because the available
bundle size measurement tools (e.g. bundlephobia.com) mistakenly counted
the entire tslib package against react-apollo, without acknowledging the
possibility of sharing that package between multiple Apollo packages. It
seemed safer to inline only the helpers we needed at the top of
lib/react-apollo.esm.js.

Now that we have a more holistic way to measure bundle sizes (#2839), and
react-apollo works better with tree-shaking tools (#2659, #2661, #2677),
we know that overall application bundle sizes benefit from sharing a
single copy of the tslib helper package, even if no tree-shaking is
happening. Of course, with tree-shaking, that one copy of the tslib
package can be shrunk to contain just the helpers that are actually used.
@benjamn benjamn self-assigned this Mar 5, 2019
@benjamn benjamn requested a review from hwillson March 5, 2019 20:11
@benjamn benjamn mentioned this pull request Mar 5, 2019
3 tasks
@benjamn benjamn merged commit 110658c into master Mar 5, 2019
@benjamn benjamn deleted the bundle-reductions-inspired-by-rollup-example-app branch March 5, 2019 23:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant