-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
How to optimize the packaged/bundle size? #10727
Comments
Hi, I am having the same question. I only use Auth and graphql. Is there anyway to reduce the size because 500kB is just to much, there must be a lot of JS code that is not relevant that can;t be treeshaken. |
Hi @chenhaiyun and @mattiLeBlanc - our team is investigating improvements to the bundle size for Amplify. We will provide you with updates when we have the next steps identified. Thank you for providing us with this feedback! |
Hi, I'm facing the same problem. I noticed that the PinPoint client from aws-sdk is also bundled, although it should not be necessary when using the Kinesis provider. (Using core & analytics) |
Hi @kevinausmh - we have observed this in our analysis as well. We are working on improving tree shaking for this scenario as part of our overall plan to reduce the bundle size of our packages. |
Tree shaking is not supported in react native fwiw, It would be ideal to restructure the library like firebase has to ensure only imported libraries are bundled. |
@blainekasten - we are thinking about that as well! We are working on a way to ensure we serve our JavaScript web and React Native customers. Thank you for the feedback - definitely on our radar! |
Hello everybody, our team has been focusing on reducing the bundle size of the Amplify library, and starting v 5.2.5, we have been able to reduce the bundle size for the below use cases:
This is only the first step in our bundle size reduction efforts. In our next major version of Amplify JavaScript, we are going to provide better mechanisms for tree-shaking that will substantially reduce the bundle size. Stay tuned - we will provide updates on this issue when we have expected timelines mapped out. Please try out the newest version of Amplify, and let us know if you are seeing the improvements I've mentioned! Your feedback is essential to helping us improve our library! |
Thank you. Can't for the new version which could drastically reduce the bundle size. |
@abdallahshaban557 I'm not sure how you're counting bytes at AWS, this is what I see in And then there are:
And then of course there are all the |
Hi @ennioVisco - can we please get your |
@abdallahshaban557 sure! Here it is: https://gist.github.com/ennioVisco/1259d50837041396507299a827dbfc5c |
Hi @ennioVisco - can you please try deleting your node_moduled folder, and then re-installing your dependencies and checking your bundle size? We are still seeing smaller bundle sizes when we tried reproducing this.
|
Ok, @abdallahshaban557 in a clean install sizes are a bit different. If the sizes you mentioned are gzipped, I guess more or less it checks out, otherwise, I get these:
with some very minor extra dependencies, not relevant for this analysis. |
Hi @ennioVisco - that is correct, the sizes mentioned are gzipped! I am glad you are seeing closer results to our analysis. |
Hello everyone, We have made some additional changes to reduce the bundle size which include reduction to the Storage category as part of The results are generated using size-limit tool v8.2.6 and bundler webpack 5.88.0. Please let us know if you are seeing these reductions in your apps.
Make sure to delete your node_modules folder and then re-install your dependencies to validate the bundle size reduction. |
I actually saw an increase in bundle size:
I am only using |
Hi @mattiLeBlanc - can you please try deleting your node_modules folder and then re-installing your dependencies? Also, can you please provide us with your package.json to further investigate this? |
@abdallahshaban557
My package file:
|
Hi @mattiLeBlanc - thank you for providing this information. Our team will get back to you! |
@bolshchikov What was the size of your |
@mattiLeBlanc I see there is a duplication of |
I can confirm that deduping |
I am not saying you should drop axios but just consider to use the same as Amplify to reduce the dependency duplication.
I am just trying to help to reduce some of the dependency on your app and Amplify, but I understand if is not possible. I couldn't reproduce the bundle size increase you mention maybe there was another dependency that change that impact the bundle size increase. Are you sure the only thing that change on your |
@elorzafe I did a compare between 2 package files and yes, this the only change. |
@mattiLeBlanc I think the changes on your App probably made the main file to be bigger, we are working very hard to make the code of Amplify small as possible. We are tracking this issue to communicate more improvements. Thanks again for your feedback! |
@elorzafe Much appreciated of course, all the work you are doing! |
I share a lot of you frustration. I think the mistake we made is to use |
Hello @mattiLeBlanc and @ennioVisco - as part of our next major version, we are moving to a more functional approach where you can import specifically the functionality that you need from our categories. We are also removing some of our underlying dependencies and relying more on browser APIs to reduce the bundle sizes further. Please let us know if you have further feedback on Bundle sizes to share. |
Hi @abdallahshaban557 |
I suppose replacing the axios dependency with fetch() API in the aws package could be a todo. Some differences to note:
The benefits of using fetch as opposed to Axios are as follows:
|
Why not stick with Axios, but maybe a newer version? Unless it adds extra weight and you can replace the missing features with some microjs packages ? |
Hi @BearCooder - that is exactly what we going to do as well! We want to remove any dependencies that can be used natively by your browser to help reduce the bundle size impacts even further. We are going to be doing the same effort for other parts of our library! |
My use case: -Very simple amplify web without any framework, the only dependency at package.json is
Bundle size: After comment de imports and the API call. 13KiB (2.01 KiB gziped) +300 KiB added just to made API.configure + API.post, probably I'll remove the aws-amplify and just made a standard fetch call. I have tested webpack and esbuild to try to treeshaking, the best that I can get is 361 KiB and 405 KiB |
Hi, how are we doing with this. Initial Chunk Files | Names | Raw Size | Estimated Transfer Size Initial Total | 1.21 MB | 258.75 kB and without those to items: Initial Chunk Files | Names | Raw Size | Estimated Transfer Size Initial Total | 836.20 kB | 178.86 kB So, 400 kb for an API class and the Auth class. That is pretty big, right? |
Hello @mattiLeBlanc - you can check out our dev preview for v6 of the Amplify JavaScript library which has our new changes to reduce the bundle size and provide a more "functional" approach to importing only the functionality you need. #12147 Once we feel confident with this new experience, we will release it in general availability. We are seeing massive reductions in bundle size with this new version. It is most definetely top of mind for us! Please let us know if you have any feedback to share after trying it out! |
I tried and left comments, I am having trouble testing it due to migration issues/differences. |
With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved! Please refer to our release announcement, migration guide, and documentation for more information. |
@cwomack I mentioned some feedback and issues in the other thread: |
Before opening, please confirm:
JavaScript Framework
Vue
Amplify APIs
Analytics
Amplify Categories
analytics
Environment information
Describe the bug
I use the amplify analytics JS SDK to send data to Kinesis. and after run npm run build, the amplify bundle size is too large. I have made a test and I found whether I use the aws-amplify library or the independent library (@ aws-amplify/core, @ aws-amplify/auth, @ aws-amplify/analytics), the packaged bundle size were the same. I want to know is there any other way to optimize the packaged/bundle size?
Expected behavior
I want to reduce the bundle size
Reproduction steps
Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
The text was updated successfully, but these errors were encountered: