Skip to content

[Python] Speed up ApproximateUnique accumulator merging - #39921

Open
sliortega295-ops wants to merge 1 commit into
apache:masterfrom
sliortega295-ops:fix/19459-approximate-unique-merge
Open

[Python] Speed up ApproximateUnique accumulator merging#39921
sliortega295-ops wants to merge 1 commit into
apache:masterfrom
sliortega295-ops:fix/19459-approximate-unique-merge

Conversation

@sliortega295-ops

Copy link
Copy Markdown

Summary

  • reuse the first ApproximateUnique accumulator instead of allocating an empty heap and reinserting every sampled hash
  • preserve the empty-iterable behavior and leave later accumulators unchanged
  • add merge identity, result, non-mutation, and empty-input coverage
  • document the improvement in CHANGES.md

This brings the Python merge path in line with the existing Java implementation and removes one accumulator's worth of heap insertions from every merge.

Fixes #19459.

Validation

  • pytest apache_beam/transforms/stats_test.py: 87 passed with the source implementation
  • rebuilt the Python extensions, then reran the same suite: 87 passed
  • focused new merge tests: 2 passed in both source and extension-backed runs
  • Ruff, YAPF, and git diff --check: passed
  • CPU microbenchmark, two identical full accumulators (median of 101 runs):
    • sample size 1,600: 0.6172 ms -> 0.2158 ms (2.86x)
    • sample size 10,000: 3.9099 ms -> 1.3734 ms (2.85x)

No GPU was used or required.

AI disclosure

The implementation, tests, benchmark, and this description were generated with OpenAI Codex at the account owner's request. Codex re-checked the final diff against the repository code and ran the validations listed above. No separate human line-by-line code review was performed before submission.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speed up merge_accumulators for ApproximateUniqueGlobally

1 participant