Minor WriteTxn optimizations - #200
Merged
Merged
Conversation
|
The deduplication of table names in WriteTxn is costly and we can consider duplicate tables as a caller bug. Let's cheaply check for duplication in SortableMutexes.Lock and panic if the same table mutex is seen twice. BenchmarkDB_NewWriteTxn-6 (arm64, 15 alternating 1s samples): time/op 501.7ns -> 453.7ns (-9.57%, p=0.000) bytes/op 216B -> 200B (-7.41%) allocs/op 5 -> 4 (-20.00%) BenchmarkDB_WriteTxn_1-6 (arm64, 15 alternating 1s samples): time/op 939.1ns -> 886.0ns (-5.65%, p=0.000) objects/sec 1.065M -> 1.129M (+6.00%) bytes/op 704B -> 688B (-2.27%) allocs/op 17 -> 16 (-5.88%) AIL:3 Signed-off-by: Jussi Maki <jussi@isovalent.com>
Remove the transaction duration field and its atomic stores from Commit and Abort. Nothing reads the field; transaction metrics derive their duration directly from acquiredAt. BenchmarkDB_NewWriteTxn (arm64, 12 alternating 1s samples): time/op 595.0ns -> 566.0ns (-4.87%, p=0.014) bytes/op 216B -> 216B allocs/op 5 -> 5 AIL:3 Signed-off-by: Jussi Maki <jussi@isovalent.com>
Replace the internal SortableMutex interface with the concrete SortableMutex type. The mutex implementation is internal and has a single implementation, so dynamic dispatch and interface storage are unnecessary. Benchmark_SortableMutex-6 (arm64, 15 alternating 1s samples): time/op 166.2ns -> 158.4ns (-4.69%, p=0.000) bytes/op 0B -> 0B allocs/op 0 -> 0 AIL:3 Signed-off-by: Jussi Maki <jussi@isovalent.com>
joamaki
force-pushed
the
pr/joamaki/txn-misc-optimizations
branch
from
September 10, 2026 13:13
512cfe6 to
5a1cef7
Compare
Co-allocate table entries with exact-sized index backing arrays for tables with zero through three secondary indexes. This removes the separate index array allocation while avoiding allocator-class waste for smaller tables. Tables with more than three secondary indexes retain the general cloning path. Compared with the initial six-slot co-allocation, exact sizing changes the transaction-opening benchmark as follows: name old time/op new time/op delta DB_NewWriteTxn_SecondaryIndexes/0-6 421.7ns 417.7ns -0.95% DB_NewWriteTxn_SecondaryIndexes/1-6 417.5ns 419.3ns ~ DB_NewWriteTxn_SecondaryIndexes/2-6 418.3ns 422.7ns +1.05% DB_NewWriteTxn_SecondaryIndexes/3-6 437.1ns 417.4ns -4.51% The zero- and one-secondary-index cases decrease from 216 B/op to 184 and 200 B/op respectively. The two-secondary-index case is unchanged at 216 B/op and 3 allocs/op. The three-secondary-index case stays at 232 B/op while improving from 4 to 3 allocs/op. The initial co-allocation also reduced transaction opening from 4 to 3 allocs/op for zero through two secondary indexes. AIL:3 Signed-off-by: Jussi Maki <jussi@isovalent.com>
Make the first NewKeySet argument non-variadic so the common singleton case does not need a variadic backing array. Add EmptyKeySet for callers that need to return no keys and adapt slice-based key producers. name old time/op new time/op delta DB_WriteTxn_1-6 857.0ns 841.3ns -1.83% DB_WriteTxn_10-6 371.1ns 350.1ns -5.66% DB_WriteTxn_100_SecondaryIndex-6 554.8ns 474.8ns -14.42% WriteTxn_1 improves from 14 to 13 allocs/op and 712 to 688 B/op, WriteTxn_10 from 7 to 6 allocs/op and 379 to 355 B/op, and the secondary index benchmark from 10 to 7 allocs/op and 491 to 419 B/op. A focused NewKeySet benchmark improves from 24 B/op and 1 alloc/op to zero. AIL:3 Signed-off-by: Jussi Maki <jussi@isovalent.com>
giorio94
self-requested a review
September 11, 2026 12:52
giorio94
approved these changes
Sep 14, 2026
Member
|
Nice! The optimizations seem reasonable to me. |
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.
writeTxnState.durationfieldinternal.SortableMutexinterface and just use the concrete type. This was leftover from when StateDB and theSortableMutexwas in cilium/cilium.index.NewKeySetto take one argument and then vararg to remove an allocation. Addindex.EmptyKeySetfor the empty case.tableIndexarray with thetableEntryfor the common number of indexes to save allocating the[]tableIndexsliceBefore:
After:
AIL:3