-
[OPIK-5270] [BE] perf: optimize feedback score CTE pipeline to reduce memory overhead (#6107)
发布于
2026-04-07 15:29:07 +00:00 -
[OPIK-5270] [BE] perf: optimize feedback score CTE pipeline to reduce memory overhead
Replace ROW_NUMBER window functions with ClickHouse-native LIMIT 1 BY
for deduplication, and collapse 9 parallel groupArray calls into a
single groupArray(tuple(...)) per feedback score chain. This eliminates
window function buffer allocation and reduces array materialization
from 9 arrays to 1 tuple array — the two biggest contributors to the
12+ GiB pipeline overhead that caused OOM on large projects.Production benchmark on customer data (17M rows):
- Before: 27.07 GiB peak memory (OOM crash at 29 GiB limit)
- After: 5.10 GiB peak memory (81% reduction, query completes)
Applied across all 12 DAO files (33 templates total):
- TraceDAO: 4 templates (trace + span feedback chains)
- SpanDAO: 4 templates
- ThreadDAO: 4 templates
- KpiCardDAO: 3 templates
- ProjectMetricsDAO: 3 templates
- ExperimentDAO: 3 templates + 2 assertion_results templates
- DatasetItemVersionDAO: 3 templates
- DatasetItemDAO: 2 templates
- ExperimentItemDAO: 1 template
- ExperimentAggregatesDAO: 1 template + 1 assertion_results template
- OptimizationDAO: 1 template
- AnnotationQueueDAO: 1 template
Zero remaining ClickHouse ROW_NUMBER dedup patterns or arrayEnumerate
index-based recombination across the entire codebase. -
perf: remove redundant FINAL keyword from feedback score queries
LIMIT 1 BY already deduplicates to the latest row per partition key,
making FINAL (which forces a merge of all data parts at read time)
redundant and expensive. Remove it from the 5 remaining DAOs to match
the pattern already used by TraceDAO, SpanDAO, ThreadDAO, ExperimentDAO,
ExperimentItemDAO, OptimizationDAO, and ProjectMetricsDAO.Files: KpiCardDAO, DatasetItemDAO, DatasetItemVersionDAO,
AnnotationQueueDAO, ExperimentAggregatesDAO (24 occurrences removed).下载附件
-