Optimize read hot path and expand benchmarks - #27
Merged
Conversation
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.
Read hot-path optimization
Point lookup: 45.18 µs → ~25 µs per 1000 queries (≈1.8x), allocations 171.88 KB → 0.
ReadOnlyTableinstances inReadOnlyDatabase—GetTableused to allocate aReadOnlyTable+TreeWalker+Dictionaryper call, which was all of the ~176 B/lookup allocation. Tables are now built once at open.KeyCompare) — the binary-search inner loop paid an interface dispatch per comparison viaIKeyEncoding.Compare. AReferenceEqualsguard on the built-in encodings inlines the compare; this also helps AOT targets (IL2CPP) where dynamic PGO never devirtualizes. Also rewroteLeafNodeReader.TryFindValueas a dedicated Equal-search loop (no per-iterationswitch (op)).TreeWalker— every lookup touches the root, so keep one retained reference and skip the cache lookup + refcount round-trip for it. This also removes the root's refcount cache line as a multi-thread contention point.PageCachemicro-optimizations — cacheIMemoryOwner.Memoryin the entry (avoids a virtual call per access) and relax the S3-FIFO frequency bump to a single CAS attempt (frequency is an approximate heuristic).Bug fix
CountRange— same patch as Fix page over-release in CountRange #26 (cherry-picked here so the count benchmark can run; merges cleanly in either order). The sibling-walk loop released the newly acquired page instead of the finished one, eventually disposing a page buffer that was still in the cache map, after which any traversal through that page spun forever.Benchmarks
immutable=1+ prepared statement reuse — ~7x faster than the naive per-query command) as comparison targets.ReadBenchmark/RangeBenchmark/CountBenchmarkover a sharedStoreBenchmarkBase.README
docs/benchmarks/), a new Performance section with raw BenchmarkDotNet tables, and fairness notes (SQLite configs, RocksDB binding overhead). Outlier bars are truncated with an axis-break glyph so the remaining bars stay readable.All 71 tests pass.
🤖 Generated with Claude Code