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

Add merge() method to ApproxMostFrequentStreamSummary as an optimization over mergeSerialized() #12236

Closed
wants to merge 1 commit into from

Conversation

deepyeet
Copy link

@deepyeet deepyeet commented Feb 1, 2025

Summary:

Context

This diff adds a merge() method which behaves equivalent to mergeSerialized().

The reason this is added is because this avoids the extra round trip serialization + deserialization that's required when calling mergeSerialized().

Rationale

The rationale here is that, the serialize function simply calls values()[i] and priorities()[i], and memcpy's the integers.

Then when we deserialize, we also simply take the values as-is and re-insert them into the target data structure.

So obviously; rather than ser + deser to perform the exact same operation, we can just copy directly.

There are a couple of considerations:

  1. StringView - Because we do not serialize, velox::StringView is still pointing at whatever other ApproxMostFrequentStreamSummary is pointing to, which means the lifetime of the string must be kept alive across both structures, even if the other one disappears. This ... feels okay, but requires consideration from the user of this class.
  2. StringView equality - seems like previous behavior is correct (insert will lookup index in priority queue and use operator== on StringView which should compare contents). So technically if all StringView point to equal strings, then this won't be problem.

Differential Revision: D68995835

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 1, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D68995835

Copy link

netlify bot commented Feb 1, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit f2280fc
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/67a11dfc159d6e0008a9922d

deepyeet pushed a commit to deepyeet/velox that referenced this pull request Feb 3, 2025
…ion over mergeSerialized() (facebookincubator#12236)

Summary:

# Context

This diff adds a merge() method which behaves equivalent to mergeSerialized().

The reason this is added is because this avoids the extra round trip serialization + deserialization that's required when calling mergeSerialized().

# Rationale

The rationale here is that, the serialize function simply calls values()[i] and priorities()[i], and `memcpy`'s the integers.

Then when we deserialize, we also simply take the values as-is and re-insert them into the target data structure.

So obviously; rather than ser + deser to perform the exact same operation, we can just copy directly.

There are a couple of considerations:
1. **StringView** - Because we do not serialize, velox::StringView is still pointing at whatever `other` ApproxMostFrequentStreamSummary is pointing to, which means *the lifetime of the string must be kept alive across both structures, even if the `other` one disappears*. This ... feels okay, but requires consideration from the user of this class.
2. **StringView equality** - seems like previous behavior is correct (insert will lookup index in priority queue and use operator== on StringView which should compare contents). So technically if all `StringView` point to equal strings, then this won't be problem.

Differential Revision: D68995835
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D68995835

…ion over mergeSerialized() (facebookincubator#12236)

Summary:

# Context

This diff adds a merge() method which behaves equivalent to mergeSerialized().

The reason this is added is because this avoids the extra round trip serialization + deserialization that's required when calling mergeSerialized().

# Rationale

The rationale here is that, the serialize function simply calls values()[i] and priorities()[i], and `memcpy`'s the integers.

Then when we deserialize, we also simply take the values as-is and re-insert them into the target data structure.

So obviously; rather than ser + deser to perform the exact same operation, we can just copy directly.

There are a couple of considerations:
1. **StringView** - Because we do not serialize, velox::StringView is still pointing at whatever `other` ApproxMostFrequentStreamSummary is pointing to, which means *the lifetime of the string must be kept alive across both structures, even if the `other` one disappears*. This ... feels okay, but requires consideration from the user of this class.
2. **StringView equality** - seems like previous behavior is correct (insert will lookup index in priority queue and use operator== on StringView which should compare contents). So technically if all `StringView` point to equal strings, then this won't be problem.

Reviewed By: Yuhta

Differential Revision: D68995835
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D68995835

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in f0a96f1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants