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

chore: Add fastpriorityqueue to concurrencyController so it scales better #26657

Merged

Conversation

robbie-c
Copy link
Member

@robbie-c robbie-c commented Dec 4, 2024

Problem

The ConcurrencyController relies on sorting a list, rather than a proper priority queue. In practice, this didn't matter, as usually there were < 20 items in the queue. I want to use this class for thousands of elements, and so this change is needed to scale better

Changes

Use a priority queue instead of a list

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Existing tests still pass

Copy link
Member

@rafaeelaudibert rafaeelaudibert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need to keep it sorted at all times, we could've optimized the original code to simply read the one with the lowest priority from the array and remove that.

That said, it's slightly more performant to use a PQ in all cases, so I'm happy with this. I assume we don't mind adding a new library? It'd be simple to inline that in our code, tbh


  • Previously: Insertion O(1), read O(n logn), deletion O(n)
  • Optimizing by not sorting (simply get the one with lowest priority): Insertion O(1), read O(n), deletion: O(n)
  • Now: Insertion O(logn), read O(1), deletion: O(logn), profit ⚡🎉

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Size Change: 0 B

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.11 MB

compressed-size-action

@robbie-c robbie-c enabled auto-merge (squash) December 4, 2024 21:03
@robbie-c robbie-c merged commit 1181b95 into master Dec 4, 2024
99 checks passed
@robbie-c robbie-c deleted the feature/add-priority-queue-to-concurrency-controller branch December 4, 2024 21:53
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.

2 participants