perf(tdigest): optimize partial aggregate compute path - #231
Merged
tisonkun merged 9 commits intoAug 27, 2026
Conversation
tisonkun
marked this pull request as ready for review
August 26, 2026 17:01
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes the T-Digest “partial aggregate” hot path by (1) decoding validated native payloads directly from borrowed slices and (2) adding a linear-time merge for already-sorted, fully-compressed centroid buffers—while keeping the public API and serialized bytes stable.
Changes:
- Add a fast merge path that linearly merges sorted centroid buffers (preserving stable ordering on equal means).
- Optimize deserialization by validating the full payload once and decoding fixed-width centroid/buffered records from slices (avoiding per-field cursor I/O).
- Add/extend regression coverage and benchmarks for serialized partial-state workloads; update changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests-integration/tests/serde_tests/tdigest.rs | Adds a byte-stability regression case covering merge after deserialize/serialize. |
| datasketches/src/tdigest/sketch.rs | Implements sorted-centroid linear merge path and slice-based native payload decoding. |
| CHANGELOG.md | Expands the Unreleased performance note to mention the new merge and decode optimizations. |
| benchmarks/tdigest/merge.rs | Adds serialized-partials merge benchmarks to reflect the optimized workload. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ariesdevil
reviewed
Aug 27, 2026
Member
Author
|
Thanks for your review @ariesdevil! I'm working on a refactor now. I noticed that we may have an opportunity to refactor the compression + merge at once. |
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.
Summary
The benchmarks model a native final-aggregate workload: deserialize 64 partial states, merge them sequentially, and query one quantile. Both changes apply without caller changes. The partial update/serialize path remains unchanged; a batch-update prototype improved that full lifecycle by only about 2% at 64 rows/state and regressed the 8-row case slightly, so it was intentionally left out.
Performance
Divan A/B runs used at least two seconds and 300 samples for the merge workloads. Times are medians from the same machine. The compute rows isolate the merge change against the branch with native direct decoding already applied; the deserialize rows compare this PR with
main.For the 64-row compute workload, allocations fall from 117 / 300.1 KB to 65 / 66.56 KB. These local microbenchmarks are directional rather than a performance contract.
Compatibility
Validation
cargo x checkcargo x testcargo x lintcargo x bench