perf: reuse expression selectors to reduce CPU and memory usage #20450
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 461 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.367
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #20450"
general
weight: 0.35
GWphua
Description
On-heap incremental ingestion creates a new aggregator for every new rollup key. For expression-based aggregators, each factorization previously rebuilt the expression bindings and row-value selector even when the selector factory and memoized parsed
Exprwere unchanged.This repeated work is significant for ingestion workloads with many rollup keys and expression metrics.
<details>
<summary>A live profiling for a task that has 6 expressions in the metric spec shows that Expression.plan accounts for 30% of all samples.</summary>
<img width="738" height="651" alt="Profile" src="https://github.com/user-attachments/assets/39c564a6-829f-465d-8fbc-9ddd3cf3c384" />
</details>
The investigation also found an existing correctness issue in
RowBasedExpressionColumnValueSelector: transformed expressions were cached using only the hash code of the array-binding list. Distinct binding lists such as["Aa"]and["BB"]have the same Java hash code and could therefore reuse the wrong transformed expression.Changes
ExprEvalSelectorCachecontract and implement it inOnheapIncrementalIndex.CachingColumnSelectorFactory.ColumnValueSelector<ExprEval>instances by the identity of the original parsed expression.get, construct, andputoperations because selector construction can re-enter the same factory while resolving input columns.ExpressionIngestionBenchmarkas a reproducible JMH benchmark for this ingestion path.Scope
IncrementalIndex.addremains single-threaded or externally synchronized; this change does not introduce concurrent selector sharing.ExpressionLambdaAggregatorFactoryis unchanged because it plans its expressions directly.Benchmark
ExpressionIngestionBenchmarkmeasures on-heap ingestion of 100,000 rows into 25,000 rollup keys using three expression metrics. Input-row construction is excluded from the measured invocation.Each variant was measured with JMH 1.37 on JDK 25 using three JVM forks, three single-shot warmup iterations, seven single-shot measurement iterations, a 1 GiB heap, and the JMH GC profiler.
| Variant | Mean elapsed | Approx. throughput | Allocation |
|---|---:|---:|---:|
| PR merge-base
d2bff3c9ec| 364.981 ± 16.502 ms | 273,987 rows/s | 985.00 MiB/op || Expression-selector cache
abe0fc5847| 129.557 ± 4.759 ms | 771,860 rows/s | 162.00 MiB/op |Selector caching reduced elapsed time by 64.5%, increased approximate throughput by 2.82x, and reduced allocation by 83.6% in this workload.
<details>
<summary>CPU usage of previous same ingestion task dropped from 10% to 5%, and heap never exeeds 6GiB for the same ingestion task in live env</summary>
<img width="780" height="990" alt="image" src="https://github.com/user-attachments/assets/926c5c3f-8d86-457b-a96f-766520614c17" />
</details>