Cache GetKeysEndOffset in BlockIter to speed up Next inner loop#14917
Cache GetKeysEndOffset in BlockIter to speed up Next inner loop#14917meta-codesync[bot] wants to merge 1 commit into
Conversation
Reviewed By: kunalspathak Differential Revision: D110209012
✅ clang-tidy: No findings on changed linesCompleted in 0.0s. |
Codex Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.🟡 Codex Code ReviewAuto-triggered after CI reached the early-review threshold — reviewing commit e57ee75 ❌ Codex review failed before producing findings. ℹ️ About this responseGenerated by Codex CLI. Limitations:
Commands:
|
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI reached the early-review threshold — reviewing commit e57ee75 SummaryClean, low-risk performance optimization that caches the result of High-severity findings (0): Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMNone. 🟢 LOW / NITL1.
|
| Context | Affected? | Safe? | Notes |
|---|---|---|---|
| Invalidate() before init | Yes | Yes | keys_end_offset_{0} gives current_=0, strictly better than old UB from uninitialized values_section_ |
| Invalidate() after init | Yes | Yes | Cached value is still valid; data_=nullptr doesn't affect it |
| CorruptionError() | Yes | Yes | Only called post-init |
| Valid() hot path | Yes | Yes | Now a single field read instead of branch + pointer arithmetic |
Immutability verification of cached inputs:
values_section_: Set only inInitializeBase()(line 590), never modified after.restarts_: Set only inInitializeBase()(line 570), never modified after.data_: Set to nullptr inInvalidate()(line 350), but the cached value avoids this dependency entirely.
Positive Observations
- The optimization targets a hot path (
Next()inner loop viaValid()checks andParseNextKeycomparisons againstGetKeysEndOffset()), where eliminating a branch and pointer subtraction is meaningful. - The
{0}default initialization is a defensive improvement. - The comment on the new field clearly documents why caching is safe.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/code_review.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
🟡 Codex Code ReviewAuto-triggered after CI passed — reviewing commit e57ee75 ❌ Codex review failed before producing findings. ℹ️ About this responseGenerated by Codex CLI. Limitations:
Commands:
|
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit e57ee75 SummaryClean, low-risk micro-optimization that caches a hot-path computation. The invariant that High-severity findings (0): Full review (click to expand)Findings🟡 MEDIUMM1.
|
| Context | Affected? | Assessment |
|---|---|---|
| Invalidate (data_ = nullptr) | Yes — returns stale cached value | Safe: current_ is set to keys_end_offset_, making Valid() return false. Pre-patch behavior with values_section_ != nullptr was technically UB (values_section_ - nullptr), so the patch is arguably an improvement. |
| InitializeBase (only caller that sets values_section_/restarts_/data_) | Yes — computes and caches | Correct: cache is set after all three inputs are assigned. |
| All other GetKeysEndOffset() callers (~18 call sites) | Yes — now use cached value | Correct: the three inputs are immutable post-initialization, so the cached value is always consistent. |
Positive Observations
- Correct placement of the cache computation after all dependent fields are assigned in
InitializeBase(). - Default member initializer
{0}ensures safe behavior ifGetKeysEndOffset()is called beforeInitializeBase()(returns 0, makingValid()return false sincecurrent_is also 0 — same as before sincerestarts_would be 0). - Good optimization target:
GetKeysEndOffset()is called inValid(),Next(),Seek(), and many other hot-path methods, so eliminating the branch has measurable benefit.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/code_review.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
Reviewed By: kunalspathak
Differential Revision: D110209012