Repository navigation
Memoize consecutive id lookups in ContextTimeSeriesTagsCollector::getGroupByID - #113580
Conversation
…GroupByID Samples tables are sorted by (id, timestamp), so the id column reaching timeSeriesIdToGroup arrives in long runs of equal values. Reusing the previous row's group skips the per-row arena serialization and hash lookup: -23% wall time on a 30-day sum(rate(...)) PromQL query over 25,600 series (62.5 billion samples total). Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [3c6c166] Summary: ✅
AI ReviewSummaryThis PR speeds up Findings❌ Blockers
Tests
Final VerdictChanges requested: the optimization must preserve the serialized-key identity semantics promised by LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/19 (94.74%) · Uncovered code |
ContextTimeSeriesTagsCollector::getGroupByID
| { | ||
| const auto * it = groups_by_id.find(keys[i]); | ||
| if (i > 0 && prev_group != INVALID_GROUP | ||
| && unwrapped.data->compareAt(i, i - 1, *unwrapped.data, /* nan_direction_hint = */ 1) == 0) |
There was a problem hiding this comment.
groups_by_id is keyed by the serialized bytes of the identifier, but this fast path reuses the previous group based on compareAt. Those equivalence relations are not the same for every ID type that timeSeriesStoreTags and timeSeriesIdToGroup currently accept: checkArgumentTypeForID still allows any comparable non-Nullable type, including floating-point IDs, and FloatCompareHelper::compare returns 0 for any two NaNs and for +0 / -0, while serializeValueIntoArena preserves the raw bits.
That means two consecutive rows can now skip the real lookup and incorrectly inherit the previous row's group even though they serialize to different keys. In the current contract that can change the returned group or suppress the expected Unknown identifier exception. Please keep the memoization keyed on the serialized representation (for example by caching the previous serialized key) or narrow the accepted ID types accordingly.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up PromQL queries over TimeSeries tables:
timeSeriesIdToGroupnow reuses the previous row's group when consecutive rows carry the same series id, skipping the per-row id serialization and hash lookup.Description
Every PromQL selector is transpiled to
SELECT timeSeriesIdToGroup(id), timestamp, value FROM timeSeriesSelector(...), sogetGroupByIDruns once per sample. It serialized the id (defaultTuple(UInt64, UUID), 24 bytes) into an arena and did a string-keyed hash lookup per row. Since the samples table is sorted by(id, timestamp), id columns arrive in long runs of equal values (typically thousands of rows per run); comparing with the previous row first makes the lookup O(runs) instead of O(rows).Measured on a TimeSeries table with 62.5 billion samples (32 cores): a 30-day
sum by(namespace)(rate(container_cpu_usage_seconds_total[5m]))query over 25,600 series drops from 39.9 s to 30.6 s cold (-23%); in a per-query CPU profile thegetGroupByID+serializeValueIntoArena+Arena::allocContinueshare (~19% of 1100 s total CPU) collapses. Query results are unchanged.🤖 Generated with Claude Code
Version info
26.8.1.901(included in26.8and later)