[CASSANDRA-21587] Megamorphic call in ClusteringPrefix.Deserializer.deserializeOne slows down readseserializeOne slows down reads - #5039
Open
koo-taejin wants to merge 1 commit into
Conversation
…eserializeOne slows down reads Avoid a third List implementation in ClusteringPrefix.Deserializer's hot path by deserializing clustering types into ImmutableList. Add regression coverage and a JMH benchmark for the memtable and SSTable header paths.
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.
Description
ClusteringPrefix.Deserializer.deserializeOne()reads clustering components in a hot partition-scan loop:clusteringTypes()is declared as List, but its runtime implementation differs by header source:This makes the List.get() call megamorphic. HotSpot can optimize one or two receiver types, but the third ArrayList receiver forces a slower interface-table dispatch.
Fix
Change
AbstractTypeSerializer.deserializeList()to return anImmutableListbuilt withImmutableList.builderWithExpectedSize(size).This removes the SSTable-only ArrayList receiver. The call site remains bimorphic:
Numbers
Production node, async-profiler, 120 seconds, 97,036 CPU samples:
JMH benchmark with controlled receiver count:
patch by koo.taejin; reviewed by for CASSANDRA-21587
The Cassandra Jira