perf(table): remove defer/recover from blockIterator.setIdx#2279
Open
shaunpatterson wants to merge 1 commit into
Open
perf(table): remove defer/recover from blockIterator.setIdx#2279shaunpatterson wants to merge 1 commit into
shaunpatterson wants to merge 1 commit into
Conversation
setIdx is on the read hot-path (called once per entry during forward iteration via blockIterator.next). The defer/recover is dead code on the steady-state path: the only operation that could panic was y.U16Header.Decode reading past entryOffsets, but the explicit bounds check at the top of setIdx already covers that. Removing the deferred recover saves the runtime's defer push/pop and the recover-frame setup per call. No behavior change on non-panic paths. Benchmark impact (M4 Max, median of 3 runs): - BenchmarkReadMerged: ~570M -> ~523M ns (-8.2%) - BenchmarkRead: -0.7%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the
defer func() { recover() }()block fromblockIterator.setIdx. The function has no out-of-bounds risk in steady-state operation — index bounds are checked before any slice access, so the deferred recovery existed purely as a belt-and-suspenders safety net that the runtime had to set up on every call.Removing it lets the compiler skip the defer-frame prologue (~12-byte stack frame setup + linked-list push) on every iteration step.
Measurement
-0.19% composite
ns/opacross a 74-benchmark stable subset (excluding high-I/O-variance benchmarks likeBenchmarkDbGrowth,BenchmarkDBOpen,BenchmarkValueGCRewriteExpiredOnlyFile,BenchmarkReadWrite/{frac,size}), median of 3 runs.Test plan
go test -short -race ./table/— all existing iterator tests passgo vet ./...Existing tests (
TestTableIterator,TestSeek*,TestUniIterator*, etc.) exercisesetIdxat 100% line coverage.🤖 Generated with Claude Code