aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
699 stars 472 forks source link

Tree-shaking the SDK #1910

Open timanderson opened 2 years ago

timanderson commented 2 years ago

The AWS Chime SDK for JavaScript is very large. I have switched to using the npm module with TypeScript and I use WebPack with ts-loader and terser to create a bundle. In my code I have:

import { ConsoleLogger, DefaultDeviceController, DefaultMeetingSession, LogLevel, MeetingSessionConfiguration, MeetingSessionStatusCode } from 'amazon-chime-sdk-js';

I was hoping that I would get a smaller file than I was getting from the singlejs demo but it has only reduced by 30K (when minimised) and is still 650K or so.

Are there any tips for reducing the size of the bundle as it seems as if WebPack's tree-shaking is not achieving much here?

ltrung commented 2 years ago

@timanderson Could you provide us more details on your use case on why you need a smaller bundle? We have not heard this request before. Is there an ideal size that you are targeting? Thanks, Trung

timanderson commented 2 years ago

Just to make our application a bit quicker to load - some of our users do not have fast internet connections. We can live with it but I was hoping to get the size down.

Tim

joey-slingshot commented 2 years ago

I'd also like to request this feature to be implemented. Currently, when I run the webpack/vite visualizer plugin for my production build, amazon-chime-sdk-js shows a file size of 1.49 MB and it takes up 25% of our total JS build.

To answer your question @ltrung:

@timanderson Could you provide us more details on your use case on why you need a smaller bundle? We have not heard this request before. Is there an ideal size that you are targeting?

This official AWS document specifically talks about the "the performance improvement due to bundle size reduction using modular packages in AWS SDK for JavaScript v3 in a real-world application".

ltrung commented 2 years ago

@joey-slingshot Is it possible to attach the webpack visualize plugin result or just a breakdown of what contributes to that 1.49MB size? Almost all of amazon-chime-sdk-js is meeting-related APIs so it is a bit different with aws-sdk js where they can bundle based on specific functionalities.

joey-slingshot commented 2 years ago

@ltrung yes, is this what you're looking for?

image

For our app, we only use the messaging functionality from Chime and not the voice or video so not having those included in our tree-shaken bundle would reduce the size significantly.

Btw, the version we're using is 3.0.0-beta.0.

gunta commented 1 year ago

We experience the same issues with the latest version: bundle size for chime is over 1.2 MB

gunta commented 1 year ago

Monitoring the bundle size would be great https://github.com/aws/aws-sdk-js-v3/issues/2816