Repository navigation
perf(sdk): drop viem's chain list from the mobile bundle - #14711
Merged
Merged
Conversation
Metro resolves viem's CommonJS build and doesn't tree-shake, so
`import { mainnet } from 'viem/chains'` pulled all 383 chain definitions
(plus the zksync/celo/op-stack/linea formatters they use) into the mobile
bundle. viem has no per-chain export, so define mainnet in the sdk with
defineChain, and add a test that it matches viem's definition.
iOS bundle: 13,272,559 -> 13,003,080 bytes min (-263 KiB),
3,152,937 -> 3,111,375 bytes gzip (-41 KiB).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: b1c24f3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Metro resolves viem's CommonJS build (
viem/_cjs/chains/index.js) and doesn't tree-shake, soimport { mainnet } from 'viem/chains'increateSdkWithServices.tspulled all 383 chain definitions into the mobile bundle, plus the zksync / celo / op-stack / linea formatters those chains reference.viem 2.21.21's
exportsmap has no per-chain subpath (only./chainsand./chains/utils), so this defines mainnet in the sdk (packages/sdk/src/sdk/utils/mainnet.ts) withdefineChain, copying viem's fields. A new test asserts ittoEquals viem'smainnet, so the copy can't drift silently on a viem upgrade.That was the only
viem/chainsimport reachable from mobile (sdk, common, mobile, spl, eth). The other imports are in web, identity-service and an sdk script, and none of them ship to mobile.Bundle size (iOS,
react-native bundle --dev false --minify true)viem/_cjs/chains/**viem/_cjs/{zksync,celo,op-stack,linea}sdk/utils/mainnet.tsThe rest of the difference is unmapped bytes and module wrappers (measured with
source-map-explorer --json).Web: Vite already tree-shakes viem's ESM build, and
web/src/services/audius-sdk/audiusSdk.tsstill imports viem'smainnetfor its relay wallet client. The sdk's inline copy therefore adds about 0.5 KB minified to web (esbuild estimate; I didn't run a full web build).Behavior
The
chainpassed to the defaultethPublicClient/ethWalletClientis deep-equal to viem'smainnet: same id, RPC defaults, ENS and multicall3 contracts. The eth RPC endpoint still comes fromservicesConfig.ethereum.rpcEndpoint.Test plan
packages/sdk:vitest run: 31 files, 249 passed / 2 skipped. Includes the newmainnet.test.tsandcreateSdkWithServices.lazy.test.ts.packages/sdk: eslint andtsc --noEmitpass🤖 Generated with Claude Code