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

refactor: Optimize IndexedPriorityQueue::addOrUpdate 20 times faster #11955

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yuhta
Copy link
Contributor

@Yuhta Yuhta commented Dec 24, 2024

Summary:
Optimize IndexedPriorityQueue to use more compact data structures (binary heap) to leverage cache locality and avoid unnecessary memory allocations. addOrUpdate is now about 20 times faster for large data (~1 million elements). This allows us to replace the custom heap implementation in ApproxMostFrequentStreamSummary with IndexedPriorityQueue.

Note that pop becomes about twice slower in the new version. This is expected because we shift some of the reordering cost from insertion time to pop time. This shall be good because for each pop, we have at least one corresponding addOrUpdate which guarantees net performance gain, and in most of the case we do
not even have pop on critical path (e.g. in case of ApproxMostFrequentStreamSummary).

Differential Revision: D67626564

@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 Dec 24, 2024
@facebook-github-bot
Copy link
Contributor

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

Copy link

netlify bot commented Dec 24, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 329d396
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/676b3e6b2c4ea000083c2832

…acebookincubator#11955)

Summary:

Optimize `IndexedPriorityQueue` to use more compact data structures (binary heap) to leverage cache locality and avoid unnecessary memory allocations.  `addOrUpdate` is now about 20 times faster for large data (~1 million elements).  This allows us to replace the custom heap implementation in `ApproxMostFrequentStreamSummary` with `IndexedPriorityQueue`.

Note that `pop` becomes about twice slower in the new version.  This is expected because we shift some of the reordering cost from insertion time to pop time. This shall be good because for each `pop`, we have at least one corresponding `addOrUpdate` which guarantees net performance gain, and in most of the case we do
not even have `pop` on critical path (e.g. in case of `ApproxMostFrequentStreamSummary`).

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

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

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants