Skip to content

perf: share checksum cache across address casings and document checksum behavior - #5510

Closed
backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/address-checksum-cache
Closed

backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/address-checksum-cache

Conversation

@backseats

Copy link
Copy Markdown
Contributor

Summary

Two small caching changes in src/utils/address/, plus docs and JSDoc for how checksums work in isAddress and getAddress.

checksumAddress: key the cache by the lowercase address

The cache was keyed by the input string, so each casing of an address was a separate entry. A common flow hashes the same address twice:

  1. decodeAbiParameters calls checksumAddress with lowercase hex, so it is cached under the lowercase key.
  2. Passing the result into another call runs isAddress (strict) in encodeAbiParameters, which calls checksumAddress with the checksummed string. That is a different key, so it misses and runs keccak again.

The checksum depends only on the lowercase address, so the cache is now keyed by it. This also replaces has + get with a single get.

isAddress: only cache the checksum comparison

The regex and lowercase checks are cheaper than an LruMap lookup, so they now run before the cache. Only the strict mixed-case comparison is cached, keyed by the address.

Measured

Node 24, warm caches unless noted.

Before After
isAddress, 1,000 lowercase addresses 245 µs 72 µs
isAddress, 1,000 checksummed (strict) 214 µs 222 µs
isAddress, 1,000 checksummed (strict: false) 210 µs 148 µs
Checksum 1,000 new addresses, then isAddress (strict) on each 17.6 ms 9.3 ms

Removing the isAddress cache entirely made the strict checksummed case about 2x slower (418 µs), so it stays for that path.

Results are unchanged. I compared outputs against the current implementation for 2,000 addresses, with and without an EIP-1191 chainId, and for mis-cased inputs to isAddress.

Docs

  • The isAddress docs said an all-lowercase address returns false in strict mode. It returns true, because it has no checksum to verify. The example now uses a mis-cased mixed-case address.
  • Added a "Checksums" section to isAddress explaining EIP-55 with a one-letter mis-casing example, and noting that all-uppercase addresses fail strict mode.
  • Added a note to getAddress that it ignores input casing and does not validate the checksum, with an example of pairing it with isAddress.
  • Added JSDoc to isAddress, getAddress and checksumAddress covering the same points.

Tests

  • Added isAddress cases for a correct checksum, a one-letter mis-casing, all-lowercase, all-uppercase, and strict: false.
  • pnpm test --run src/utils/address src/utils/abi/{encodeAbiParameters,decodeAbiParameters,getAbiItem,encodePacked}.test.ts src/accounts: 417 passed.
  • tsc -b and Biome are clean.

@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@backseats is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ab25990

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

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

jxom commented Nov 15, 2026

Copy link
Copy Markdown
Member

Thanks @backseats! Superseded by #5514, which keeps your commit and adds a test for the EIP-1191 cache keys plus a couple of doc fixes.

@jxom jxom closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants