Cache type codes to eliminate shared_ptr overhead in hot paths#465
Open
iskakaushik wants to merge 1 commit intoClickHouse:masterfrom
Open
Cache type codes to eliminate shared_ptr overhead in hot paths#465iskakaushik wants to merge 1 commit intoClickHouse:masterfrom
iskakaushik wants to merge 1 commit intoClickHouse:masterfrom
Conversation
ColumnDecimal: cache data_type_code_ to avoid shared_ptr<Type> temporaries and dynamic_cast via As<>() on every Append/At call. ColumnLowCardinality: cache index_type_code_ to replace VisitIndexColumn (which called Type()->GetCode() + dynamic_cast per invocation) with direct static_cast in getDictionaryIndex, appendIndex, and removeLastIndex. Benchmarked with a 10M row insert (43-column schema, 100K rows/batch, LZ4 1MB chunks) over 10 interleaved iterations. Block build time improved by 7.0% (3477ms → 3233ms, t=30.8, p≈0) and grand total by 1.6% (12086ms → 11890ms, t=6.4, p<0.001). Insert phase itself is unchanged as it remains LZ4-compression-bound.
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.
data_type_code_at construction to avoidshared_ptr<Type>temporaries anddynamic_castviaAs<>()on everyAppend(Int128)andAt()call. The underlying storage type (Int32/Int64/Int128) is invariant after construction.index_type_code_to replaceVisitIndexColumn()— which calledType()->GetCode()(creating ashared_ptrtemporary) plusdynamic_castper invocation — with directstatic_castingetDictionaryIndex,appendIndex, andremoveLastIndex. Cache is updated inLoadBodyandSwapwhereindex_column_may change.Profiling showed
shared_ptr<Type>destructors consuming 5.54% of CPU inColumnDecimal::Appendand 3.91% inVisitIndexColumn, making these the highest-impact non-compression optimizations available.Estimated gain: ~7-9% combined insert throughput improvement.