Skip to content

perf: look up the dedupe cache once per request - #5517

Closed
backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/dedupe-single-lookup
Closed

backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/dedupe-single-lookup

Conversation

@backseats

Copy link
Copy Markdown
Contributor

Summary

withDedupe called promiseCache.get(id) twice on a cache hit:

if (promiseCache.get(id)) return promiseCache.get(id)!

LruMap.get also refreshes the entry (get, has, delete, set), so every hit did that work twice. This stores the first lookup and returns it. Behavior is unchanged.

Benchmark

Cache hits against a full 8,192-entry LruMap (Node 24, 2M lookups per run, two runs each):

ns per hit
Before 109, 114
After 77, 68

That's small per call, but withDedupe sits in front of every deduplicated request (block number, chain ID, etc.).

Tests

  • Added behavior: looks up the cache once per call. It spies on promiseCache.get during a cache hit and expects exactly one call. It fails on main and passes with this change.
  • src/utils/promise/withDedupe.test.ts: 5 passed.
  • Biome is clean.

@vercel

vercel Bot commented Nov 15, 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 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f2904c

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! Landing the source change in #5521, with you as co-author. The new test used vi.spyOn with a call count, which our test conventions don't allow, and the change has no observable behavior to test, so #5521 drops it.

@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