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

refactor: switch to smaller dependencies to reduce bundle size #525

Merged

Conversation

Mini-ghost
Copy link
Contributor

fast-deep-equal and klona serve as alternatives to lodash-es's isEqual and cloneDeep, respectively. They offer more lightweight options that do not fall short in performance compared to lodash-es.

Here are the differences in bundle sizes before and after:

Before

dist/vue3-lottie.es.js   48.58 KiB / gzip: 10.85 KiB
dist/vue3-lottie.cjs.js   21.69 KiB / gzip: 7.66 KiB

After

dist/vue3-lottie.es.js   13.55 KiB / gzip: 3.32 KiB
dist/vue3-lottie.cjs.js   6.88 KiB / gzip: 2.54 KiB

All examples tested in the playground have been working normally. I am very open to understanding if there are any other considerations.

@Mini-ghost Mini-ghost requested a review from megasanjay as a code owner March 2, 2024 03:04
Copy link

vercel bot commented Mar 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue3-lottie ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2024 3:05am

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

PR Type: Refactoring

PR Summary: This pull request focuses on optimizing the bundle size of the vue3-lottie package by replacing lodash-es with fast-deep-equal and klona. These changes aim to maintain functionality while significantly reducing the library's footprint, as demonstrated by the provided bundle size comparisons before and after the refactor.

Decision: Comment

📝 Type: 'Refactoring' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Unsupported files: the diff contains files that Sourcery does not currently support during reviews.

General suggestions:

  • Ensure comprehensive testing around the new dependencies to cover all scenarios previously handled by lodash-es. This includes unit and integration tests that specifically address deep equality checks and deep cloning functionalities.
  • Consider adding performance benchmarks or updating existing ones to evaluate the impact of the new dependencies on the library's performance. This will help in identifying any potential bottlenecks or performance regressions introduced by the change.
  • Enhance documentation to guide users through the transition, especially those migrating from older versions. Highlighting the rationale behind the switch, any notable differences in behavior, and steps for migration could greatly assist users in adapting to the changes.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -13,7 +13,8 @@
"prettier": "npx prettier --write ."
},
"dependencies": {
"lodash-es": "^4.17.21",
"fast-deep-equal": "^3.1.3",
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Given the switch from lodash-es to fast-deep-equal and klona, it's crucial to ensure that the existing unit tests cover scenarios where deep equality checks and deep cloning are performed. If such tests are not present, I recommend adding them to verify that the new dependencies behave as expected in all use cases previously covered by lodash-es.

@@ -13,7 +13,8 @@
"prettier": "npx prettier --write ."
},
"dependencies": {
"lodash-es": "^4.17.21",
"fast-deep-equal": "^3.1.3",
"klona": "^2.0.6",
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Considering the replacement of lodash-es's cloneDeep with klona, it's important to validate the cloning functionality, especially in edge cases such as circular references, or cloning complex objects like functions, Dates, RegExps, etc. If tests covering these scenarios are missing, adding them would ensure klona meets the requirements.

@@ -13,7 +13,8 @@
"prettier": "npx prettier --write ."
},
"dependencies": {
"lodash-es": "^4.17.21",
"fast-deep-equal": "^3.1.3",
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Please ensure that the integration tests also reflect the change in dependencies. It's important to verify that the integration points where isEqual and cloneDeep were used still work as expected with fast-deep-equal and klona. This might involve updating mock data or test scenarios to cover new edge cases introduced by the dependency change.

@@ -13,7 +13,8 @@
"prettier": "npx prettier --write ."
},
"dependencies": {
"lodash-es": "^4.17.21",
"fast-deep-equal": "^3.1.3",
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): It's commendable that the bundle size has been significantly reduced by switching dependencies. However, it's equally important to ensure that performance benchmarks, if any, are updated or added to reflect the impact of these changes. Performance tests can help in understanding if the new dependencies introduce any latency or execution bottlenecks compared to lodash-es.

@@ -13,7 +13,8 @@
"prettier": "npx prettier --write ."
},
"dependencies": {
"lodash-es": "^4.17.21",
"fast-deep-equal": "^3.1.3",
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): The switch to fast-deep-equal and klona is a significant change that could affect the functionality of the library. It would be beneficial to add a section in the documentation or README explaining this change for users migrating from older versions. This documentation should ideally include any steps users might need to take or any notable differences in behavior.

@megasanjay
Copy link
Owner

Thank you for the PR! Will take a look

@megasanjay megasanjay changed the base branch from main to v3.3 March 17, 2024 00:43
@megasanjay megasanjay merged commit a9bb4d8 into megasanjay:v3.3 Mar 17, 2024
6 checks passed
megasanjay added a commit that referenced this pull request Mar 17, 2024
* fix: ensure `loadLottie` is called after the component mounted (#527)

* fix: ensure `loadLottie` invoke after `lottieAnimationContainer` is mounted

* refactor: remove unnecessary `nextTick`

* perf: educe the unnecessary use of `ref` (#526)

Co-authored-by: Sanjay Soundarajan <[email protected]>

* refactor: switch to smaller dependencies to reduce bundle size (#525)

* 🐛  fix: performance improvements and suspense bug fixes

* 🔖 chore: prep for releasing v3.3

* 🔖 chore: prep for releasing v3.3 beta

---------

Co-authored-by: Alex Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants