Skip to content

perf: look up open cores by key before hashing the discovery key - #190

Draft
danielAsaboro wants to merge 3 commits into
holepunchto:mainfrom
danielAsaboro:perf/key-index
Draft

danielAsaboro wants to merge 3 commits into
holepunchto:mainfrom
danielAsaboro:perf/key-index

Conversation

@danielAsaboro

Copy link
Copy Markdown

Stacked on #189; review that one first. Only the last commit is new here.

get({ key }) on a core that's already open still runs crypto.discoveryKey (BLAKE2b) in _auth before it can look the core up. This adds a second slot index over the same dense core array, keyed by the core's public key, and checks it first. The hash only runs on a miss.

  • Cores opened by discovery key alone join the key index once their key is known: through the Fix key edge case #182 path, or the first get({ key }) that falls back to a lookup by discovery key.
  • If a core opened by discovery key replaces a keyed one, the old key entry is removed first.
  • No state is copied: entries are the tracked cores themselves, added and removed with them, so nothing can go stale.

validation

test/cores.js now also checks the key index against a reference Map, including the replace path above. That test caught a stale-entry bug in an earlier draft. Node and Bare 55/55, npm run lint clean.

numbers

benchmark base branch ratio wins
get({ key }) on an open core, vs #189 1,068 ns 181 ns 0.17 11/11
session get + ready + close, vs #189 2,357 ns 930 ns 0.39 11/11 (a run under heavy machine load gave 0.37, 9/11)
cores.get(dk), vs #189 80 ns 62 ns 0.77 9/11 (parity)
get({ key }), vs main 1,307 ns 233 ns 0.18 11/11
session churn, vs main 3,100 ns 1,207 ns 0.39 11/11

Same method as #189: both checkouts in one process, 1000 open cores, 11 alternating paired runs.

This branch has not been deployed

No deployments
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