Repository navigation
Conversation
Parse parameters once per call, build un-prefixed hex and join it once, precompute integer bounds, and cache function selectors per ABI item. Values outside the fast path go through the existing per-parameter code, so output and errors are unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e1b3-ce83-72d3-b448-f29dd09b6e57 Co-authored-by: jxom <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: de46219 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Published pnpm add viem@pr-5525
pnpm add [email protected] |
Fold the address, bool, number and string checks into the fast path and keep only the bytes encoder as a fallback, so the encoder adds less to the bundle. Raise the size limits the change still crosses by 0.5 kB. Fix the test value types. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e1b3-ce83-72d3-b448-f29dd09b6e57 Co-authored-by: jxom <[email protected]>
a6f2ac8 to
77f7ba6
Compare
|
Bundled into #5543 as its own commit, so this PR is superseded. Closing in favour of the bundle. |
Speeds up
encodeAbiParametersandencodeFunctionData(B3 from the perf audit).Changes
encodeAbiParametersparses each parameter once per call into a small descriptor (kind, array length, tuple components, integer bounds). Before, it re-ran the type regexes,startsWith,splitand{ ...param, type }spreads for every value.+=, and joined once at the end. This replaces aconcatHex(reduce+replace('0x', '')) and asize()per part. The finaljoinflattens the string, so callers retain the same size as before.2n ** BigInt(size)per value.bytesNtypes) go through the existingencodeBytes. Malformed parameters (missingtype, tuples withoutcomponents, unknown types) throw the same errors at the same point.prepareEncodeFunctionDatacaches selectors in aWeakMapkeyed by the ABI item, andencodeFunctionDataconcatenates the selector directly. Entries die with the ABI. A caller that mutates an ABI item after first use keeps the old selector.Bundle size (needs a maintainer decision)
The encoder adds about 430–570 B (brotli) to the bundles that include it.
mainhas only about 300 B of headroom onprivateKeyToAccountand about 700 B onviem/actions, so this PR raises five limits by 0.5 kB:mainimport * from 'viem'(esm)require('viem')(cjs)viem/account-abstractionprivateKeyToAccountviem/actions(Measured locally with the same
tscbuild and size-limit; the cjs entry wasn't measured locally.)Benchmarks
SKIP_GLOBAL_SETUP=true ./node_modules/.bin/vitest bench -c ./test/vitest.config.ts --project core --run src/utils/abi/encodeAbiParameters.bench.ts src/utils/abi/encodeFunctionData.bench.ts, same machine,origin/mainvs this branch (ops/s):encodeAbiParametersnested struct (existing)fulfillAdvancedOrder(existing)uint256[1000]address[1000]string[100]tuple[300]encodeFunctionDataERC-20transferencodeFunctionDatamulticall3aggregate3, 100 callsMemory per call (
node --expose-gc, 512 MiB young generation):uint256[1000]encodeFunctionDatatransferCorrectness
origin/main: a scratch harness ran 12,547 inputs per seed over 5 seeds (about 63k inputs, about 22k of them errors). It compared output, error class and error message.bytes0,bytes33,bytesbytes,uint7,tuplewithout components,string[0],tuple[0][].components, non-arraycomponents, missingtype.encodeFunctionDatamatched on about 100 inputs per seed across the ERC-20, multicall3 and Seaport ABIs, with the selector cache cold and warm.AbiParameters.fuzz,AbiParameters.differential.fuzz(encode vs ethersAbiCoder,encodeFunctionDatavs ethersInterface) andAbiParameters.adversarial.fuzz(mutated decode throws onlyBaseErrors) all passed atFC_NUM_RUNS=20000. A deliberately brokenbytesNpadding made 4 of the 8 properties fail, so the harness catches regressions.bytesis left-padded, and the first invalid value throws.Tests
src/utils/abi(Anvil-backed): all pass.readContract,multicall,simulateContract: all pass exceptsimulateContract > node errors > fee cap too low, which fails the same way onorigin/mainin this environment.tsc -p src/tsconfig.json: passes. Biome: clean.