Repository navigation
[perf-agent:assets-controller/MulticallClient.ts] Encode/decode Multicall3 aggregate3 directly instead of via ethers Interface - #11100
Closed
Prithpal-Sooriya wants to merge 5 commits into
Conversation
encodeAggregate3, decodeAggregate3Response and decodeUint256 now lay out and read the fixed aggregate3/(bool,bytes)[]/uint256 shapes directly (string word layout + BigInt word read) instead of going through ethers Interface/Reader machinery on every call. Byte-identical calldata and values, same throw behaviour on malformed shapes, enforced by the full MulticallClient test suite. Bench (MetaMask Mobile hermes CLI, 2400 balance calls): 601ms -> 20ms.
The balanceCallData cache now also remembers the original-case spelling of each account, so repeated lookups hit without allocating a lowercase key; encodeAggregate3 hoists the constant words (allowFailure 1, 0x60 offset, address padding) out of the per-call loop. Bench: 20ms -> 18ms (2400 balance calls, hermes CLI).
Contributor
Author
|
thanks for this finding - but we already found insights here: #11010 |
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
encodeAggregate3,decodeAggregate3ResponseanddecodeUint256now lay out / read the fixed Multicall3 ABI shapes (aggregate3((address,bool,bytes)[]), its(bool,bytes)[]output, and thebalanceOfuint256 word) directly — string word layout + aBigIntword read — instead of going through the ethersInterface/Readermachinery on every batch.0x60offset,0x1, address padding) are hoisted out of the per-call loop.Draft / DO-NOT-MERGE — generated by the assets performance research agent; on-device confirmation still required.
Why
From the MetaMask Mobile Hermes profile (scheduled perf run
39731720623at commit9b830f28), this path is the dominant assets-owned cost in the regressed Asset View scenario (tracked in #37813: 20.4s vs 11.0s baseline, 1.86×) and 8 other scenarios (4.2–7.1s each):Every encode/decode went through ethers
Interfaceparsing and dynamic coder dispatch; the shapes here are fixed, so the same bytes can be produced/read with direct word arithmetic.Bench
The real
MulticallClientsource is bundled to a single Hermes script (MetaMask Mobilehermes-engineCLI,-O) that replays a locked parity corpus — 14 batches covering mixed success/failure, native+ERC-20, empty/short/odd/oversized return data, mismatched counts, malformed hex, retry (3 attempts) andfallbackToSingleCallssemantics — then runs a timing workload of balance calls (~15% native) with a warm callData cache. Median of 3 process runs; every run must passSELF_CHECK=OK(byte-identical provider call sequence + field-identical results) and the fullMulticallClientvitest suite, including the existing "identical calldata to regular Ethers implementation" test.Per-call cost is flat across the sweep, so the win is not a bench-shape artifact. The
.auto/directory in this branch contains the bench (harness, generator, corpus) for reproducibility.Testing
yarn vitest run packages/assets-controller/src/data-sources/evm-rpc-services/clients/MulticallClient.test.ts --coverage.enabled=false— 38/38 pass, incl. byte-identical calldata vs ethers and count-mismatch error message.yarn vitest run packages/assets-controller --coverage.enabled=false— 1325 passed, 5 pre-existing expected-fails, no type errors.BigIntis standard JS (available on the RN Hermes runtime) and adds no new dependency.🤖 Generated with Claude Code