Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve KLL Sketch perf for non-grouped queries #22619

Merged
merged 1 commit into from May 1, 2024

Conversation

ZacBlanco
Copy link
Contributor

Description

Defers calculations of memory sizes for Kll sketches unless using a grouped query.

Motivation and Context

The current method for calculating memory usage has a hidden cost. Within getEstimatedKllInMemorySize we call getSerializedSizeBytes. The code for the serialized bytes size actually serializes the entire internal state to a byte array first before returning the length. This is expensive and should be avoided.

I am working on a PR to the upstream library to add a less-costly method but until released, I would like to fix this as non-grouped execution doesn't need the memory accounting for every sketch input.

Impact

N/A

Test Plan

N/A

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== NO RELEASE NOTE ==

The current method for calculating memory usage has a hidden cost.
Within getEstimatedKllInMemorySize we call getSerializedSizeBytes.
The code for the serialized bytes size actually serializes the entire
internal state to a byte array first before returning the length. This
is expensive and should be avoided.

I am working on a PR to the upstream library to add a less-costly method
but until released, I would like to fix this as non-grouped execution
doesn't need the memory accounting for every sketch input.
@ZacBlanco ZacBlanco marked this pull request as ready for review April 29, 2024 13:24
@ZacBlanco ZacBlanco requested a review from a team as a code owner April 29, 2024 13:24
@aaneja
Copy link
Contributor

aaneja commented Apr 30, 2024

Can you paste the call stack or method in datasketches-java that ends up serializing the internal state for size calculation ?

@ZacBlanco
Copy link
Contributor Author

You can find the relevant section here

However, for the KllDoublesSketch, the copying doesn't occur. The call chain eventually gets to here where getNumRetained() is just a few array index lookups. I have a local branch where I'm trying to replace the implementation for doubles with this version of the sketch.

They don't have a sketch implementation for raw longs yet, but I am planning on contributing that to the library so that for the native numeric types we can get better performance creating the sketches. You can see some of the perf numbers I was getting in this comment

@tdcmeehan tdcmeehan self-assigned this Apr 30, 2024
@ZacBlanco ZacBlanco merged commit c209f50 into prestodb:master May 1, 2024
57 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.

None yet

3 participants