perf(rocksdb): Add VoidNamespace fast-path and reusable read buffer#2
Open
nateab wants to merge 1 commit intofeature/rocksdb-zerocopy-key-serializationfrom
Open
Conversation
Add two optimizations to the RocksDB state backend: 1. VoidNamespace fast-path in SerializedCompositeKeyBuilder: Short-circuit namespace serialization for VoidNamespace (most common in non-windowed state) by writing the single byte directly instead of going through full serializer dispatch. 2. Reusable value buffer for read operations: Replace the allocating db.get(CF, key) API with db.get(CF, ReadOptions, key, keyOff, keyLen, valueBuf, valOff, valLen) which writes into a pre-allocated reusable buffer, eliminating one byte[] allocation per state read. Applied to: - RocksDBValueState.value() - RocksDBMapState.get() and contains() - AbstractRocksDBAppendingState.getInternal() (reducing/aggregating) JMH benchmark results vs master: valueGet: +16.0% (793 -> 921 ops/ms) mapGet: +5.6% (97 -> 103 ops/ms)
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
SerializedCompositeKeyBuilder— short-circuits namespace serialization for the most common namespace type (non-windowed state) by writing the single byte directly instead of full serializer dispatchdb.get(CF, key)API withdb.get(CF, ReadOptions, key, keyOff, keyLen, valueBuf, valOff, valLen)which writes into a pre-allocated reusable buffer, eliminating onebyte[]allocation per state readRocksDBValueState.value(),RocksDBMapState.get()/contains(), andAbstractRocksDBAppendingState.getInternal()(reducing/aggregating states)Benchmark Results (vs master)
Note: These results include the cumulative effect of all optimizations on
feature/rocksdb-zerocopy-key-serialization(write-path ByteBuffer API) plus this PR's read-path changes.Design Decisions
db.get(ColumnFamilyHandle, ReadOptions, ByteBuffer, ByteBuffer)variant requires direct ByteBuffers only (assertion in FRocksDB 8.10.0). Thebyte[]variant avoids this complexity while achieving the same allocation elimination.ListDelimitedSerializer.deserializeList()which needs full byte[]. Follow-up optimization.Test plan