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
Find low-hanging fruit to minimize bundle size #684
Comments
This is a pretty urgent issue; the current versions of apollo-client and react-apollo seem to add 178kb (minified) to a bundle: lodash is a mess here, I know a PR recently got merged, but perhaps more can be done? lodash should be used very sparingly client side. For some reason graphql-tag is pulled in anyway when I only use the webpack loader. Is that necessary? Once you add essentials such as react, react-dom, react-router, polyfills etc. along with your own application code you get ~500kb minified. |
@jaydenseric is there an easy way to set up a script that will generate the above image for some set of packages? That would be super helpful. |
Also, I think the gzipped size is the most relevant number, which is only 50kb? |
I think this will get rid of some of the huge things like We could also probably eliminate the graphql-tag dep when using the webpack loader for queries, but I'm curious to see how much space the actual parsed graphql queries take up. Looks like this diagram doesn't include any queries at all. Thanks for reopening this conversation - I find this topic really useful but we currently don't have good enough tools set up to keep track of the size situation, and would really appreciate your help on that. |
th0r/webpack-bundle-analyzer is pretty neat, it serves an interactive webpage that can be zoomed and panned after webpack runs. I haven't fully explored the CLI to work out the most efficient way to add a more permanent analyse script to a project. My webpack config returns an array; for seperate server/client bundles. This chokes webpack-bundle-analyzer for some reason so I have to manually comment out the server config every time I run the script. |
If you did figure it out a PR to this repository would be super appreciated. |
Oh, and keep in mind that those pictures, I think, are post webpack v2 tree shaking and uglify dead code elimination. If users don't have both setup it could be different. Perhaps in this repo we could:
It would be interesting to be able to see before and after tree shaking / dead code elimination, perhaps it could run a build for 2 different configs and open the analysis in two tabs using different ports. |
To be honest though I doubt there is much a difference with and without tree shaking. But that strategy seems like a good direction to go. So I just removed all lodash deps from graphql-anywhere, I wonder how much that will help. |
Related to tree shaking: #746 (add module entry to package.json). |
I think I just saved 7kb (minified and gzipped - removed lodash.countby and lodash.merge): #1043 |
Added a new analyze script to the package.json that makes it possible to inspect what modules make it into the published package and how efficiently it bundles in a webpack v2 project. The script runs a compilation and builds the analyze test project (that only imports this library) with webpack and the webpack-bundle-analyzer plugin in production mode. Once complete the plugin opens your browser to an interactive analysis at http://localhost:8888. See discussion: apollographql#684 (comment).
BTW, we removed lodash for a lot more savings in #1122 |
I think we've taken care of what qualifies as low-hanging fruit for now, so I'll close this issue. 22.7Kb is pretty small, if you ask me! |
Hi, it would be great if this issue could be re-opened regularly. In our current Next.js app's main bundle, the Apollo Client is taking an increasingly large place. Here is a picture worth a thousand words: Out of 178 kbz of shared dependencies in our node_modules, here is a breakdown:
For a total of 42.51 kbz, not including possible shared hoisted dependencies like lodash. We also plan on adding more, like We're obviously big fans of the Apollo Client, deeply thankful for the library, and I hope you'll take this as coming from a good place. (And yes, there is a lot more to say about our breakdown, and moment.js is going out very soon). |
Edit: I followed up with an issue on Likewise
Is there any plan to move |
I also noticed that zen-observable is included multiple times, but it's already in my project in addition the below instances, although I see one version below is the typescript version. These are the non gzipped sizes. |
Hi @sbrichardson, Since I commented on that (already closed) issue, I landed a PR with I don't think anyone is going to see this closed issue, and I would recommend opening a new one with your bundle size map chart. Personally, I am currently not working in a project with Cheers |
The bundle size keeps growing slowly. It would be good to make an effort at reducing the size during a refactor, by checking the size of external dependencies and seeing what large packages we could replace with something else.
The text was updated successfully, but these errors were encountered: