Eliminate cache-populate completion wait after upstream EOF

perfloop/tag · SYNC WAIT

https://perfloop.ai/t/oss/case_mtzbwvz133

Verdict

VERIFIED · settled 2026-08-09 · merged as tigrisdata/tag#148

What happened: The paired measurements met the required improvement.

Hypothesis

A static control-flow check of `streamFromUpstream`, `fetchAndBroadcast`, `setupCacheListener`, and `Broadcaster.Complete` showed a completion cycle: after the upstream body reaches EOF, this method selects on `cacheErrCh` or a 100 ms timer; `fetchAndBroadcast` calls `Complete` only after this method returns; and `setupCacheListener` normally sends its result only after its `listener.Chunks()` range ends, which `Complete` closes. Thus the normal successful cache-populate path cannot report completion before this wait releases. The source check establishes the ordering, but no runtime latency trace was run, so the user-visible impact remains a hypothesis. The cadence is once per successful cacheable full-GET miss, not per streamed chunk, and the removed delta is the post-EOF 100 ms timeout on that path. A case session should reproduce this with a cacheable GET and instrument upstream EOF, `streamFromUpstream` return, `Broadcaster.Complete`, HTTP end-of-stream, and eventual cache-write completion: the current trace should show an approximately 100 ms EOF-to-completion gap, while the change should remove that gap without reducing later cache-hit success or losing late cache-write errors.

Change to test: Do not synchronously await the cache listener result before returning from the upstream stream. Use only a nonblocking immediate result observation or a detached late-error observer, while preserving the cache listener's detached write context, populate-slot release, and error logging; returning lets broadcaster completion close the cache listener and lets cache population finish independently.

Where it lives

perfloop/tag · handlers/server.go

Evidence

cacheable-full-get-miss-handler-completion · 10 sample pairs

metric baseline candidate paired median change confidence range required result
ns/op 101216495 572750 −99.4% (−100582624) −100814219 to −100452552 < 0 PASSED

Checks: 4 of 4 passed. Verification: no defect found.

Timeline