Skip to content

perf+obs(store): reuse exists→get directory lookup; count L3 prefetch probes (0.6.4) - #22

Merged
flymysql merged 2 commits into
cursor/discovery-poll-logging-49dafrom
cursor/dir-lookup-exists-get-handoff-49da
Jun 2, 2026
Merged

perf+obs(store): reuse exists→get directory lookup; count L3 prefetch probes (0.6.4)#22
flymysql merged 2 commits into
cursor/discovery-poll-logging-49dafrom
cursor/dir-lookup-exists-get-handoff-49da

Conversation

@flymysql

@flymysql flymysql commented Jun 2, 2026

Copy link
Copy Markdown
Owner

1. perf: reuse directory lookup across exists→get

SGLang's HiCache prefetch resolves a prefix in two stepsbatch_exists() (hit length) then batch_get() (pull pages) — which issued two directory RPCs for the same keys (the exists booleans were thrown away, then get re-resolved locations). The owner lookup itself is a local consistent-hash computation (no network) and is already batched per owner, so this removes the redundant second RPC.

batch_exists() now fetches full locations (non-None == present, pool or disk — same semantics as the old directory.exists()) and primes the resident hit prefix into a one-shot handoff cache. The imminent batch_get()_fetch() pops those primed locations, skipping the second lookup.

Correctness: primes are popped on use and short-TTL (1s), so a consumed location is only ever as stale as the exists→get gap (sub-ms). Always on, never older than one prefetch handoff — distinct from the opt-in directory_read_cache_ttl (unchanged, default off). Size-capped with an expired-entry sweep. Covers v1, v2 (batch_exists_v2 extra pools), and single-key exists().

New counter: peercache_directory_lookups_saved_total.

2. obs: make the L3 prefetch path observable

read_requests == 0 alone can't tell why there are no reads. Added:

  • peercache_exists_requests_totalbatch_exists calls (SGLang L3 prefetch probes)
  • peercache_exists_pages_found_total — pages reported present by those probes

Decision table:

Signal Meaning
exists_requests == 0 SGLang's prefetch never reached the storage backend (prefetch disabled / not configured)
exists_pages_found == 0 (probes > 0) probing but directory miss — key derivation / shard / timing
found > 0 but read_requests == 0 found in L3 but not fetched — local L1/L2 hit or prefetch policy aborted

Tests

  • test_exists_get_handoff_saves_directory_lookup: the get reuses all primed locations (counter += hits) and re-resolves once consumed (one-shot).
  • Full suite: 54 passed.

Version → 0.6.4.

Open in Web Open in Cursor 

cursoragent and others added 2 commits June 2, 2026 04:42
SGLang's HiCache prefetch resolves a prefix in two steps -- batch_exists()
to find the hit length, then batch_get() to pull those pages -- which issued
two directory RPCs for the same keys. batch_exists() now fetches full
locations and primes the resident hit prefix into a one-shot handoff cache;
the imminent batch_get() consumes (pops) them, skipping the second lookup.

Primes are popped on use and short-TTL (1s), so a consumed location is only
ever as stale as the exists->get gap -- always on, never serving a location
older than one prefetch handoff (unlike the opt-in directory_read_cache_ttl).

Adds a directory_lookups_saved counter and a contract test asserting the
get reuses primed locations and re-resolves once they are consumed.

Co-authored-by: 兰州小红鸡 <flyphp@outlook.com>
read_requests==0 alone can't distinguish 'SGLang never probed L3' from
'probed but didn't fetch'. Add exists_requests (batch_exists calls) and
exists_pages_found (pages reported present) so the prefetch path is
observable end to end:
  - exists_requests==0            -> prefetch never reached the backend
  - exists_pages_found==0         -> probing but directory miss (key/shard)
  - found>0 but read_requests==0  -> found, not fetched (local hit/policy)

Co-authored-by: 兰州小红鸡 <flyphp@outlook.com>
@cursor cursor Bot changed the title perf(store): reuse directory lookup across exists→get (0.6.4) perf+obs(store): reuse exists→get directory lookup; count L3 prefetch probes (0.6.4) Jun 2, 2026
@flymysql
flymysql marked this pull request as ready for review June 2, 2026 06:14
@flymysql
flymysql merged commit d9ecc73 into cursor/discovery-poll-logging-49da Jun 2, 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