Skip to content

feat(tuple): serialize union results without cloning summaries #321

Open

Description

@tisonkun

Problem

Tuple union serialization currently requires union.to_sketch(ordered).serialize(). to_sketch() clones retained entries, including each user-defined summary. For summaries containing heap data, this may allocate and copy substantial data that serialization only needs to borrow. The summary encoder itself already accepts &self.

Suggested approach

  • Add direct union-result serialization that borrows summaries while applying the final theta, capacity, and ordering rules.
  • For ordered output or capacity selection, consider sorting/selecting references to entries instead of cloning summary values. Share result preparation and encoding with the compact sketch where appropriate.
  • Keep the existing TupleSummaryValue encoding contract. Avoid adding a Clone bound solely for serialization; this does not imply removing the cloning requirements of union updates.
  • Begin with TupleUnion. Evaluate reuse for TupleIntersection and mutable-sketch compaction/serialization as follow-ups. Preserve the distinction between an uninitialized intersection and an empty result.

Start with datasketches/src/thetafamily/tuple/union.rs, tuple/sketch.rs, tuple/serialization.rs, and common/union.rs. Coordinate changes to shared Theta-family result preparation with the Theta serialization work. PR #317 provides the corresponding HLL motivation.

Validation

Compare with the existing compact-result path across ordering choices, theta/capacity trimming, empty/singleton results, and fixed- and variable-size summaries. Exercise summary encoding and subsequent merges with a realistic heap-backed summary. Verify existing compatibility tests and measure time and allocations for both small numeric summaries and larger heap-backed summaries before claiming a performance gain.

Follow CONTRIBUTING.md for changelog entries, integration-test placement, serialization fixtures, and the required checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions