Skip to content

Comments

refactor: rework the worker manager for performance#110

Merged
1Lucas1apk merged 1 commit intoPerformanC:v3from
ToddyTheNoobDud:v3
Nov 1, 2025
Merged

refactor: rework the worker manager for performance#110
1Lucas1apk merged 1 commit intoPerformanC:v3from
ToddyTheNoobDud:v3

Conversation

@ToddyTheNoobDud
Copy link
Collaborator

Changes

Added this.workerToGuilds = new Map() on constructor, this goes from an O(n) to a O(1), providing better speed

Added this.workersById = new Map(), this also enables O(1) lookups for more speed

Reworked scaleWorkers(), this removes the excessive interactions of filtering and array creations, converted to a for const with a single pass interaction

Added caching on scalingConfig to avoid repeating objects acess

Added batching to stats updates (every 100ms) to reduce overhead

getBestWorker has been rewrited to use the least-loaded worker instead of using round-robin for selecting workers.

Improved the failure history to use a slice(-5) instead of shift(), slice uses O(k), beign slighly more performant than shift()

Why

This should reduce the garbage collection overload/pressure, also should improve the workers distribution for loading and reduce the overhead while maintaining more speed

Checkmarks

  • [ X ] The modified endpoints have been tested.
  • [ X ] Used the same indentation as the rest of the project.
  • [ X ] Still compatible with LavaLink clients.

Additional information

i request for an actual testing on this before "merging" if this happens, i want to check if this actually helps reducing the cpu and memory load, any feedback will be good

Signed-off-by: toddynnn <86982643+ToddyTheNoobDud@users.noreply.github.com>
@1Lucas1apk 1Lucas1apk merged commit 49e3b64 into PerformanC:v3 Nov 1, 2025
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