Repository navigation
Conversation
Parse parameters once per call, read offsets, lengths and integers straight from the word, create the cursor's DataView lazily, track re-reads with a bitset, and share one TextDecoder. The read limit, budget and bounds checks are unchanged. Co-authored-by: jxom <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-01a1e1b3-ce83-72d3-b448-f29dd09b6e57
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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. |
🦋 Changeset detectedLatest commit: 66b7881 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 |
|
Published pnpm add viem@pr-5532
pnpm add [email protected] |
|
Bundled into #5543 as its own commit, so this PR is superseded. Closing in favour of the bundle. |
Speeds up
decodeAbiParameters(B2 from the perf audit). The decoder's safety limits are unchanged: the 8192 recursive read limit, the 32×bytes/stringbudget and every bounds check.Changes
getArrayComponents,split('bytes'),split('int'),hasDynamicChildand{ ...param, type }spreads for every element. A cross-callWeakMapcache was measured during the audit and didn't help, so descriptors are rebuilt per call and retain nothing.bytesToNumber, so unsafe values throw the sameIntegerOutOfRangeError.uint256/int256: read as fourgetBigUint64limbs from the cursor'sDataViewinstead ofbytesToHex+BigInt.subarray(nosliceBytescopy). Bools are checked in place, withbytesToBoolkept for invalid words so the error is identical.TextDecoder.src/utils/cursor.ts, internal):DataViewis created on first use.Map<number, number>. The bitset grows when a read starts past the end: a shortbytesNin a final partial word moves the cursor up to 32 bytes past the end, and zero-width reads there must still count against the limit.uint256[0][4294967295]after such abytes1run 4 billion iterations.positionReadCountandgetReadCountwere only used by the cursor itself and are gone.Bundle size (needs a maintainer decision)
Adds about 400–700 B (brotli). Measured locally with the same
tscbuild and size-limit:mainimport * from 'viem'(esm)require('viem')(cjs)viem/account-abstractionviem/actionsviem/chainsCI measures about 200–300 B more than this local build. #5525 (encoder) raises the same limits, so whichever lands second needs another bump.
Benchmarks
SKIP_GLOBAL_SETUP=true ./node_modules/.bin/vitest bench -c ./test/vitest.config.ts --project core --run src/utils/abi/decodeAbiParameters.bench.ts,origin/mainvs this branch (ops/s):fulfillAdvancedOrder(existing static struct)uint256[1000]address[1000]string[100]aggregate3return, 500 resultsaddress[1000]is dominated bychecksumAddress(keccak per address), which is outside this change. After this change,hexToByteson the input is the largest remaining cost of most decodes. Decoding straight from the hex string is the next step, not done here.Memory per call (
node --expose-gc):uint256[1000]address[1000]Correctness
origin/main: a scratch harness ran about 89.7k inputs per seed over 5 seeds (about 449k inputs, about 208k of them errors). It compared values, error class and error message.bytes0,bytes33,bytesbytes,uint7,tuplewithout components) and malformed ABI objects.BaseErrors) all passed atFC_NUM_RUNS=20000.string[0],bytes[0]) throwsPositionOutOfBoundsErroronmainand on this branch. The round-trip test leaves zero-length arrays out.Tests
src/utils/abi,src/utils/encoding,src/utils/blob,cursor,readContract,multicall,call(Anvil-backed): all pass exceptcall > errors > gas fee is less than block base fee, which fails the same way onorigin/mainin this environment.tsc -p src/tsconfig.json: passes. Biome: clean.