Skip to content

CASSANDRA-21683 Reuse scratch key bytes in PartitionIndexBuilder - #5181

Open
rustyrazorblade wants to merge 1 commit into
apache:trunkfrom
rustyrazorblade:21683-bti-index-key-alloc-6.0
Open

rustyrazorblade wants to merge 1 commit into
apache:trunkfrom
rustyrazorblade:21683-bti-index-key-alloc-6.0

Conversation

@rustyrazorblade

Copy link
Copy Markdown
Contributor

Cut the byte-comparable key-encoding allocation on the BTI partition-index build path. addEntry re-encoded the same one or two keys about four times per partition through diffPoint, cut, and the trie's prev re-read, which is about nineteen short-lived ByteSource, Multi, varargs, and escaper objects per partition.

Encode each key's comparable bytes once into a reusable scratch byte[], do diffPoint as an array compare, and feed the trie a fixed-length source over the captured bytes. A three-slot ring keeps the previous key stable while the trie re-streams it on the next add. Output is byte-identical.

JMH PartitionIndexBuildBench with -prof gc: gc.alloc.rate.norm falls about 288 bytes per partition, -59.3% at one million keys, with no change to build time.

@rustyrazorblade rustyrazorblade changed the title Reuse scratch key bytes in PartitionIndexBuilder CASSANDRA-21683 Reuse scratch key bytes in PartitionIndexBuilder Sep 17, 2026
Cut the byte-comparable key-encoding allocation on the BTI partition-index
build path.  addEntry re-encoded the same one or two keys about four times
per partition through diffPoint, cut, and the trie's prev re-read, which is
about nineteen short-lived ByteSource, Multi, varargs, and escaper objects
per partition.

Encode each key's comparable bytes once into a reusable scratch byte[], do
diffPoint as an array compare, and feed the trie a fixed-length source over
the captured bytes.  A three-slot ring keeps the previous key stable while
the trie re-streams it on the next add.  Output is byte-identical.

JMH PartitionIndexBuildBench with -prof gc: gc.alloc.rate.norm falls about
288 bytes per partition, -59.3% at one million keys, with no change to build
time.
@rustyrazorblade
rustyrazorblade force-pushed the 21683-bti-index-key-alloc-6.0 branch from 86651b2 to cd40156 Compare September 19, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant