Skip to content

perf: refresh access LRU recency on gated reads - #210

Merged
ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-geqjvcqra9
Aug 15, 2026
Merged

ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-geqjvcqra9

Conversation

@perfloop

@perfloop perfloop Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A gated access-time LRU hit used Peek, so reads within AccessUpdateDelay did not refresh cache recency. Under capacity pressure, a hot key could be evicted from the in-memory gate and then re-enter the update batch on its next read, causing avoidable access-index work.

Fix

Use Get for the access-time lookup. It preserves the stored timestamp and existing delay gate while promoting every hit. Uncapped storage and FIFO eviction do not use this path.

Add a capacity-two regression and an end-to-end Storage.Get benchmark that runs the updater worker and access-index flush. The benchmark is a deterministic capacity-pressure guardrail, not a production eviction-rate model.

Tests

make test-storage TESTRUN='^TestAccessUpdater_'

Workload: steady-state capacity-two gated Storage.Get access group

Metric Before After Change
hot-key-readmissions/op 1 0 100% lower
access-index-reads/op 3 2 33.3% lower
access-index-key-writes/op 9 6 33.3% lower
Checks: 1 passed.

Generated by Perfloop. Human sponsor: Tomas Senart. Measurements and checks.


Note

Low Risk
Localized change to async access-time batching and test-only Flush API; no auth or data-model changes.

Overview
Fixes access-time gating so reads within AccessUpdateDelay still count as LRU hits. timeGateUpdate now uses Get instead of Peek on the in-memory access-time cache, promoting hot keys without changing the delay gate or re-batching stale timestamps.

Flush now returns how many distinct updates were written; external flush requests pass that count back through the flush channel. Tests assert the flush count, and new coverage includes a capacity-two LRU recency regression plus an end-to-end Storage.Get benchmark under capacity pressure.

Reviewed by Cursor Bugbot for commit fdced87. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refreshes in-memory LRU recency for gated reads while preserving the stored access timestamp. It also adds deterministic capacity-pressure coverage and exposes flush batch counts for benchmark metrics.

  • Replaces the access-time cache’s non-promoting lookup with an LRU-promoting lookup.
  • Adds a capacity-two regression test for hot-key residency.
  • Adds a Storage.Get benchmark covering updater and access-index flush work.
  • Changes Flush to return the number of batched access updates.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking accuracy issue in the newly returned flush count when RocksDB writes fail.

The LRU promotion follows the intended single-worker access-tracking model, while flushBatch returns its pre-write batch size even after logging a failed write and discarding the entries.

Files Needing Attention: storage/access_updater.go

Important Files Changed

Filename Overview
storage/access_updater.go Correctly promotes gated LRU hits, but the new Flush count reports attempted entries rather than successfully persisted entries on RocksDB write failure.
storage/access_updater_test.go Adds focused regression and benchmark coverage for capacity-pressure behavior without introducing a concrete functional defect.

Reviews (1): Last reviewed commit: "perf: refresh access LRU recency on gate..." | Re-trigger Greptile

Comment thread storage/access_updater.go
return 0
}

batchSize := len(a.batch)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Flush count includes failed writes

When RocksDB rejects either batch write, flushBatch logs the error, discards the pending updates, and still returns the pre-write batch size. The new Flush result therefore counts entries that were not persisted, making callers and benchmark metrics report work that did not occur.

Knowledge Base Used: Storage Lifecycle: Compaction, Eviction, and Deletion

@ovaistariq ovaistariq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against source (gate semantics, LRU construction, delay/bucket constants, all Flush callers). Approve.

Core fix (Peek → Get) is correct

The gate LRU's stored value is the last-persisted access time (Add happens on persist inside timeGateUpdate), and its recency should track read traffic. With Peek, a hot key that's read constantly-but-always-gated looks idle, gets evicted from the gate under capacity pressure, and its next read is a miss → a spurious full access-index rewrite (1 point read + 3 key writes per readmission, per flushBatch). Get fixes exactly that with nothing else changing:

  • Get doesn't mutate the stored value → the 5-min persist gate (DefaultAccessUpdateDelay) is preserved bit-for-bit.
  • Single caller goroutine (run) + lru v2's internal locking → no concurrency concern.
  • The one real tradeoff: the old code accidentally re-persisted hot keys more often under gate pressure; now hot-key persisted staleness is bounded by the 5-min delay. Eviction buckets are 1-hour (AccessBucketFormat = "2006010215"), so a ≤5-min skew is immaterial to eviction order — within the design contract.

Impact bound

Prod gate capacity = DefaultAccessUpdateBufferSize = 100k keys, so the bug only bites when >100k distinct keys are read within the delay window (high-cardinality small-object reads). Real fix, small blast radius, essentially free — and the PR body is upfront that the benchmark is a guardrail, not a production model.

Plumbing (Flush() → int)

Handshake checks out: the unbuffered send succeeds only when run commits to the flush branch, the caller then blocks on <-done, run sends the count (the trailing close(doneCh) is redundant-but-harmless), and the shutdown path returns 0. The sole non-test caller (FlushAccessUpdates) legally ignores the return.

Tests

The capacity-2 regression test genuinely discriminates — under the old Peek code the fourth key evicts hot, whose re-read re-enters the batch with a new timestamp and breaks the Equal(firstHotUpdate, …) assertion. b.Loop() is fine on CI's Go 1.24.2.

One minor follow-up (non-blocking)

Agree with the existing Greptile finding: flushBatch captures batchSize before the RocksDB writes and still returns it on a write error (which logs, discards the batch, and drops the updates). The return only feeds tests/benchmark, so it's an observability wart rather than a production bug — but returning 0/actual-written on the error path is a two-liner that would keep the new assertions honest under injected failures. Fine as a follow-up.

@ovaistariq
ovaistariq merged commit f7afdfc into main Aug 15, 2026
13 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-geqjvcqra9 branch August 15, 2026 03:41
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.10.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants