Repository navigation
Conversation
hashStruct passes a map of type hashes through encodeData and encodeField, so encodeType, the dependency walk, the sort and keccak run once per struct type instead of once per struct value, such as every element of a struct array. Co-authored-by: jxom <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-01a1e1b3-ce83-72d3-b448-f29dd09b6e57
🦋 Changeset detectedLatest commit: 017b820 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 |
|
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. |
|
Published pnpm add viem@pr-5541
pnpm add [email protected] |
|
Bundled into #5543 as its own commit, so this PR is superseded. Closing in favour of the bundle. |
Speeds up
hashTypedData(B7 from the perf audit). Outputs and errors are unchanged.Changes
hashStructcreates aMapof type hashes and passes it through the internalencodeData/encodeField.encodeType(dependency walk, sort, string build) and itskeccak256now run once per call instead of once per struct value, such as every element of aPermitDetails[].hashTypedDataandhashDomaingo throughhashStruct, so they get it too. No public signature changes.src/utils/signature/hashTypedData.bench.tswith EIP-2612 Permit, Permit2PermitBatch(100 details) and a Seaport order (100 consideration items).Benchmarks
SKIP_GLOBAL_SETUP=true ./node_modules/.bin/vitest bench -c ./test/vitest.config.ts --project core --run src/utils/signature/hashTypedData.bench.ts,origin/mainvs this branch (ops/s), 3 runs:PermitBatch, 100 detailsA single Permit has one struct per hash, so nothing repeats. Its time is spent in
validateTypedData,encodeAbiParametersandkeccak256.Correctness
origin/main: a scratch harness comparedhashTypedData,hashStructandhashDomainvalues, error class and message against a copy of theorigin/mainmodule.Node[]children); nested and fixed struct arrays (Cell[][],Cell[2]); a struct nameduint256[]; fresh random valid instances.TypedData.getSignPayload(independent implementation).hashTypedData,verifyTypedData,recoverTypedDataAddress,typedData,signTypedData(account and wallet action), publicverifyTypedDataandexperimental/erc7739(13 files, 153 tests) pass.tsconsrcpasses.Size
At most +137 B locally (
viem/account-abstraction), within the current limits. Other perf PRs (#5525, #5532, #5533, #5539, #5540) bump the same limits, so whichever lands later may need a rebase there.