Skip to content
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

feat(BrandLoadingScreen): improve lottie animations #1235

Merged
merged 11 commits into from
Sep 13, 2024
Merged

Conversation

marcoskolodny
Copy link
Collaborator

@marcoskolodny marcoskolodny commented Sep 6, 2024

In order to verify the improvements, I've modified locally the size-stats example and used bundle analizer to compare the results.

  1. Used an online tool to compress the lottie JSON files for Vivo-new logo. This improved in 20% the total size of the lotties:

    • Before:
      MicrosoftTeams-image

    • After:
      MicrosoftTeams-image (1)

  2. I noticed that the main bottleneck was using lottie-react to render the lotties. This lib imports lottie-web, and that library is quiet heavy. Some people recommended importing lottie-light from lottie-web and using it as replacement for the default one.

    What I've done is copying a minimized version of (lottie-react into our repository and adapted it to use lottie-light instead of lottie-web. This caused a pretty big improvement (over 50% of the total size of the lib).

    • Before:
      MicrosoftTeams-image (2)

    • After:
      MicrosoftTeams-image (3)

In total, by using the exact same example in size-stats, we can see that the bundles size has been reduced by over 160kb:

  • Before:
    MicrosoftTeams-image (4)

  • After:
    MicrosoftTeams-image (5)

🗒️ Note

The size stats comment in this PR only shows the improvements caused by compressing the vivo lotties. The ones obtained by replacing the lottie library are not visible because the example page in the size-stats doesn't use a BrandLoadingScreen component (and the lotties are imported lazily). Refer to the images I've attached in this description to see the impact.

Copy link

github-actions bot commented Sep 6, 2024

Size stats

master this branch diff
Total JS 12.2 MB 12.2 MB -32.4 kB
JS without icons 2.04 MB 2.01 MB -32.4 kB
Lib overhead 68.2 kB 68.2 kB 0 B
Lib overhead (gzip) 16.6 kB 16.6 kB 0 B

Copy link

github-actions bot commented Sep 6, 2024

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

Copy link

github-actions bot commented Sep 6, 2024

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-gc9eykp2t-flows-projects-65bb050e.vercel.app

Built with commit 6dadf8f.
This pull request is being automatically deployed with vercel-action

@marcoskolodny marcoskolodny marked this pull request as ready for review September 6, 2024 17:07
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from https://github.com/Gamote/lottie-react/blob/main/src/components/Lottie.ts and modified in order to fix some errors and adapt to our use cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used https://www.lottiemizer.com/ to compress the JSON files

const deregisterList = listeners.map((listener: Listener) => {
// In Mistica we only use these two events. If we try to add the event listener for all the other
// events from the listeners array, some runtime errors appear (and TS complains about wrong types).
const misticaAnimationEvents: Array<AnimationEventName> = ['complete', 'loopComplete'];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add the listeners conditionally only for these two events because I was getting runtime (and TS) errors otherwise.

I've analyzed this and we should be fine by adding only these two events, because we never use the other ones in Mistica

@marcoskolodny marcoskolodny changed the title feat(BrandLoadingScreen): compress lottie animations feat(BrandLoadingScreen): improve lottie animations Sep 6, 2024
Copy link
Collaborator Author

@marcoskolodny marcoskolodny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested rendering the BrandLoadingScreen in the Mistica storybook, and I can verify the improvements I've measured locally with bundle analyzer. As you can see, the total size of mistica bundles appears to have been reduced by around 170kb when using the BrandLoadingScreen (over a 10% improvement in the total bundle size for this page).

Also, notice how the bundle that contains the main. prefix is faster now (567ms vs 186ms).

Before:

image

After:
image

src/lottie/index.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using yarn patch to import the light version of lottie-web instead of the default one that the library uses. This is the main improvement

@marcoskolodny marcoskolodny added this pull request to the merge queue Sep 13, 2024
Merged via the queue into master with commit e7dc87f Sep 13, 2024
11 checks passed
@marcoskolodny marcoskolodny deleted the lottie-poc branch September 13, 2024 13:18
tuentisre pushed a commit that referenced this pull request Sep 27, 2024
# [16.1.0](v16.0.0...v16.1.0) (2024-09-27)

### Features

* **BrandLoadingScreen:** improve lottie animations ([#1235](#1235)) ([e7dc87f](e7dc87f)), closes [/github.com/airbnb/lottie-web/issues/1184#issuecomment-411586909](https://github.com//github.com/airbnb/lottie-web/issues/1184/issues/issuecomment-411586909)
* **Form fields:** allow blocking copy/cut ([#1251](#1251)) ([8fd2838](8fd2838))
* **Form fields:** improve accesibility of errors ([#1246](#1246)) ([e35a99e](e35a99e))
* **PhoneNumberField:** Custom formatter support + lazy load libphonenumber on demand ([#1244](#1244)) ([2ee88e9](2ee88e9))
* **PosterCard, DisplayMediaCard:** allow using srcSet for backgroundImage ([#1253](#1253)) ([3b3d85f](3b3d85f))
* **Rating, InfoRating:** new components ([#1196](#1196)) ([02c91f6](02c91f6))
* **SearchField, TextField:** support inputMode prop ([#1249](#1249)) ([fe31eca](fe31eca))
* **Sheet:** lazy load sheet implementations ([#1250](#1250)) ([40fecdd](40fecdd))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 16.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants