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

optimize: SDK bundle size by ~100kb #478

Merged

Conversation

VladimirMikulic
Copy link
Contributor

We use Safe Wallet SDK in our commercial Web3 application.
The main problem thus far has been huge bundle size.

After deeper investigation, I found out that inside SDK whole ethers package was imported.
Moreover, ethers itself isn't architected in the way so it can be tree shaken.

Given that SDK only uses ethers in a few places (message hashing and function data encoding), I've decided to migrate to alternative viem which comes with much better TypeScript support and most importantly, the whole package is 3x smaller and optimized for tree shaking.

After testing these changes in our production, we experienced a significant drop from 504kb to 359kb in bundle size.
I expect other apps to have similar result. (100 - 150kb drop depending on bundler configuration)

@changeset-bot
Copy link

changeset-bot bot commented May 11, 2023

🦋 Changeset detected

Latest commit: cdc7c61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@safe-global/safe-apps-sdk Major
@safe-global/safe-apps-provider Patch
@safe-global/safe-apps-react-sdk Patch
@safe-global/safe-apps-test-app Patch
@safe-global/safe-apps-web3modal Major
example-safe-apps-wagmi-cra Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented May 11, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@VladimirMikulic
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@VladimirMikulic
Copy link
Contributor Author

recheck

@mmv08
Copy link
Member

mmv08 commented May 11, 2023

Hey, could you please revert all changes to the package.json and add a changeset instead? There's a comment above from the changeset bot that contains the instructions :)

@VladimirMikulic VladimirMikulic force-pushed the optimize/sdk-bundle-size branch from 7db6ff1 to 5a24667 Compare May 11, 2023 14:12
@VladimirMikulic
Copy link
Contributor Author

Appreciate the fast reply @mmv08. Changeset has been added.

@hammeiam
Copy link

Hey all, just wondering what the latest was on this PR?

@VladimirMikulic
Copy link
Contributor Author

@hammeiam PR waiting review. Feel free to subscribe to PR to get updates as we progress.

Copy link
Member

@mmv08 mmv08 left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@malonehedges
Copy link

when can we expect this to ship? it seems like it's been approved 2 weeks ago

Copy link

@worm-emoji worm-emoji left a comment

Choose a reason for hiding this comment

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

lgtm!

@malonehedges
Copy link

cc @yagopv @dasanra @DaniSomoza

@mmv08 mmv08 changed the base branch from main to development June 21, 2023 12:56
@mmv08 mmv08 merged commit dfb7fae into safe-global:development Jun 21, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2023
@VladimirMikulic VladimirMikulic deleted the optimize/sdk-bundle-size branch July 11, 2023 13:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants