refactor(store,cache)!: optimize cache restore as O(1)#3134
refactor(store,cache)!: optimize cache restore as O(1)#3134julienrbrt wants to merge 5 commits intomainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
|
Claude finished @julienrbrt's task in 2m 40s —— View job Code ReviewThis PR replaces the O(n) cache restore (scanning block history) with a compact binary snapshot key ( Issues1. Bounded spin loop in for range 1_000 {
current := c.maxDAHeight.Load()
if daHeight <= current { return }
if c.maxDAHeight.CompareAndSwap(current, daHeight) { return }
}If 1,000 CAS attempts all fail under extreme concurrent contention the update is silently dropped. For a correctness-critical field like for {
current := c.maxDAHeight.Load()
if daHeight <= current { return }
if c.maxDAHeight.CompareAndSwap(current, daHeight) { return }
}2. _ = c.store.SetMetadata(ctx, c.snapshotKey(), encodeSnapshot(entries))A failed snapshot write means the node restarts without the latest in-flight window. There's no logging, no metric—the failure is completely invisible. Even a 3.
4. PR title says "O(n)" — should be "O(1)" The PR title reads "Optimize cache restore as O(n)" but the actual optimization goes from O(n) → O(1). The body and commit messages are correct; the title has the typo. 5.
Observations
The manual byte-by-byte hex encoding is correct and efficient, but harder to audit than Snapshot binary format lacks a version/magic byte The 16-byte-per-entry format is compact, but there is no version marker. A future format change (e.g. adding a third field) would silently corrupt existing snapshots or require a migration. A single leading version byte would be cheap insurance.
What's Good
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3134 +/- ##
==========================================
+ Coverage 60.87% 61.00% +0.12%
==========================================
Files 113 113
Lines 11695 11677 -18
==========================================
+ Hits 7119 7123 +4
+ Misses 3773 3758 -15
+ Partials 803 796 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overview
Optimize cache restore as O(n) + prep v1.0.0.