Skip to content

perf(base): avoid rescanning key prefixes in Map.has - #2210

Open
toprameen wants to merge 3 commits into
bendlang:mainfrom
toprameen:carry-map-has-key-cursor
Open

toprameen wants to merge 3 commits into
bendlang:mainfrom
toprameen:carry-map-has-key-cursor

Conversation

@toprameen

Copy link
Copy Markdown
Contributor

Map.has reuses the key cursor from Map.get so deeper splits can resume from the previous character. Set.has uses the same path. The extended fixture checks hits through both recursive branches and misses with long and short queries.

Median times from alternating local runs with prebuilt queries and 50% hits:

Set Lookups Native C Bun Node
16 short identifiers 480,000 16 → 19 ms 145 → 93 ms 71 → 69 ms
16 namespaced identifiers 112,000 106 → 88 ms 1,006 → 126 ms 625 → 70 ms
Two long keys with one late split 128,000 66 → 97 ms 266 → 127 ms 164 → 65 ms

The two-key case pays to initialize a suffix and reaches a leaf immediately. I kept the cursor implementation for the gains on deeper tries and included the shallow native cost above.

@toprameen
toprameen marked this pull request as ready for review November 19, 2026 21:29
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.

1 participant