Skip to content

perf(tdigest): scan centroids for dense CDF and PMF batches - #305

Merged
tisonkun merged 3 commits into
apache:mainfrom
Xuanwo:xuanwo/tdigest-minimal-optimization-b
Oct 27, 2026
Merged

tisonkun merged 3 commits into
apache:mainfrom
Xuanwo:xuanwo/tdigest-minimal-optimization-b

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

CDF and PMF currently repeat a centroid binary search for every ordered split point. Share a forward cursor for dense batches, while retaining binary search for sparse batches. Both use the existing tail, equal-mean, weight, and interpolation logic; the CDF loop and weight accumulation remain shared.

Benchmark

Measured aa23deaa051e71c18beed66907f86ca23f35199e against 675e3e123fda6da19657d345038252b16adc2ebb on an isolated EC2 c7i.2xlarge (Xeon Platinum 8488C), Rust 1.99.1 release defaults, CPU 2. Baseline calibration selects fixed work near 300 ms; both variants perform exactly the same count in seven alternating pairs. These are measured whole-batch totals.

Fixed workload Count per sample Before After Speedup (before / after)
Prebuilt frozen CDF, 100 split points 85,760 289 ms 108 ms 2.68×
Prebuilt frozen CDF, 512 split points 17,920 295 ms 111 ms 2.65×
Prebuilt frozen PMF, 100 split points 84,480 287 ms 109 ms 2.64×
Prebuilt repeated-value CDF, 100 split points 98,560 285 ms 128 ms 2.24×
Build from 100,000 inputs, then CDF with 100 split points 59 290 ms 287 ms 1.01×
Prebuilt frozen CDF, 1 split point 4,224,000 290 ms 290 ms 1.00×
Prebuilt frozen CDF, 6 split points 1,113,600 286 ms 287 ms 1.00×
Prebuilt frozen CDF, tail split points 857,600 295 ms 294 ms 1.00×
Prebuilt frozen PMF, tail split points 832,000 285 ms 288 ms 0.99×
Prebuilt repeated-value frozen PMF, tail split points 780,800 289 ms 292 ms 0.99×

Before/after are median batch times. Speedup is the median of seven paired before/after ratios; above 1× is faster, below 1× is slower. Unrounded ratios determine the result; integer milliseconds are only for display. Medians of paired ratios need not equal the ratio of median times. These totals do not describe a single request or application latency.

Prebuilt rows count complete CDF or PMF calls on prepared digests. The lifecycle row counts complete construct/update/CDF/destroy workflows, each ingesting 100,000 items; it includes pending compression. Its paired before/after ratios range from 0.992 to 1.020, so this run does not establish a complete-lifecycle gain. The benefit is concentrated in dense queries on existing digests; the tail PMF control is slightly slower. Input generation is outside timing in both variants.

Across all 41 measured cases, the largest median latency regression is 1.21%, below the 5% limit used for this comparison. The limit applies separately to each case, including controls; it is not an average across workloads or a guarantee for every individual sample or environment. Targeted baseline/candidate correctness fingerprints match exactly.

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-proven improvement.

But you may follow #307 (comment) as well.

@tisonkun
tisonkun enabled auto-merge (squash) October 27, 2026 07:51
@tisonkun
tisonkun merged commit 41686e2 into apache:main Oct 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants