-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Issues with tree-shaking in v3 beta #5686
Comments
@billyjanitsch any chance you could try things out with If you're still noticing issues though, definitely let us know. Thanks! |
Thanks for following up, @hwillson! I'll try it out this weekend and let you know. |
@hwillson Unfortunately it's not fixed; it actually got even worse. 🙁 After upgrading |
Thanks for the additional details @billyjanitsch. Apollo Client 3 is tree-shakable, and working as expected. I'm not sure how the
AC3 adds more functionality in for sure, so it's a bit bigger. We're always working on reducing bundle sizes, and have changes coming that will help with this, but for now everything is working as expected. As far as tree-shaking goes, if you want to validate it's working, you can const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
module.exports = {
devtool: 'source-map',
mode: 'production',
plugins: [
new UnminifiedWebpackPlugin()
]
} Then after import { Observable, useQuery } from '@apollo/client';
console.log(Observable, useQuery) then rebuild, open the |
Thanks for the reply, @hwillson! Unfortunately, I think we're talking past each other a little.
I linked to the Boost branch in the OP. It's exactly the same source code as the AC branch. The only difference is that one depends on Boost and the other depends on AC. Both sizes are computed by running I understand that the entire size of You can actually see this in your Bundlephobia links if you scroll down to the "Exports Analysis" sections. This section shows the size of the bundle if you only import each individual export from the library, rather than importing the whole thing. The reported size of the AC doesn't fail to tree-shake all cases; only some of them. That's why this isn't evident from the fixtures in the repo. |
Another way to verify this is by adding Sure enough, even though the code only imports
You're right that |
Got it @billyjanitsch, thanks for clarifying. This is all definitely known. We balanced a few tradeoffs when restructuring AC3, and are currently favoring the majority of use cases when using That being said, we do offer smaller entry points when people are looking for less. For example:
Your example of just wanting We're constantly looking for ways to improve all of this, so if you have any concrete suggestions on areas we can improve (that don't hinder the out of the box getting started |
Heads up: we're not quite ready to publish |
Hi @benjamn! Thanks for following up. Unfortunately, In fact, (Of course, the total size of In any case, I appreciate the effort you've put in to fix this!
@hwillson Thanks for your comment. To follow up on this point, I had been precompiling all GraphQL queries in my app using When I upgraded to the AC3 beta, I noticed a massive increase in bundle size, and found that it was because this dependency, along with various other parts of AC I wasn't using, were no longer being tree-shaken. I figured this specific scenario would be harder to explain in an issue, and I thought it might be mistaken for the incidental changes that AC3 made related to wrapping |
@billyjanitsch That may be related to #6687. I'll comment here when I've resolved that issue. |
I've been looking for some free time to dig into how AC's modules are structured to try to help out. From a brief look, though, I have two ideas:
If I'm right about either or both of these theories, this issue should be fixable without sacrificing the top-level exports of AC3 providing the out-of-the-box experience you're looking for. The fix would be a matter of shuffling around some of the modules, particularly the re-exports. |
@billyjanitsch Bundlephobia's Exports Analysis is bugged and not reliable: pastelsky/bundlephobia#364 |
@benjamn any updates on this? |
@hwillson per your note above with the smaller entry points, the main issue I am having is with There are a couple thoughts which may be of assistance:
Just a couple theories, hope that helps. |
@benjamn @hwillson I'm not a webpack expert but I have dug further as possible as I can, maybe this finding will help you addressing the issue. Before we continuing analyze the problem I have provide small repo for replication, and run In this repo, the repo only have 4 important modules from AC3:
In addition, you can see
As you can see at the above image, we almost import entire library of AC3 (~30kb gzipped). I have marked with red bordered rectangle as an example of module that we have not explicitly used but it is part of our large bundle size contributor. Let's narrow our scope to simplify the write-up, we will use
import { useQuery } from '@apollo/client/react/hooks';
import PokemonQuery from '../../queries/Pokemon/query.graphql';
const PokemonList = () => {
const { data, loading } = useQuery(PokemonQuery, {
variables: {
first: 10
}
});
...
export * from "./useApolloClient.js";
export * from "./useLazyQuery.js";
export * from "./useMutation.js";
export * from "./useQuery.js";
export * from "./useSubscription.js";
export * from "./useReactiveVar.js"; With my current understanding, the code snippet above is not harm at all for tree shaking optimization and we expect webpack (and terser) will do remove unwanted react hooks module such as
I’m trying to proof the concept here by adding If you compare above image with the earlier given image, and with the consideration of what the repo only import |
Thanks for all the detailed info @miqdadfwz! We will dig into this before the Apollo Client v3.4 launch is finalized (though probably during the Release Candidate phase, since improving tree-shakeability should be relatively a transparent optimization, not a change in functionality). |
Hello @miqdadfwz and others! We've released a change in |
Intended outcome:
I would expect these bundles to be roughly the same size:
and:
Actual outcome:
The
apollo-boost
bundle is 7.6 KiB, whereas the@apollo/client
bundle is 94.2 KiB.How to reproduce the issue:
Compare this branch to this branch. To produce the bundle size measurements, check out either branch and run
npm run build
.Versions
For the
apollo-boost
bundle:The
@apollo/client
one is the same except:The text was updated successfully, but these errors were encountered: