perf(worker): rewrite voice-event sweep as bisect, drop to O(n log n)#69
Merged
Conversation
The voice-event aggregation block was the dominant cost on heavy
packages and the reason why the worker was hitting the 15-min Lambda
timeout:
for join in sorted_joins:
next_leave = next((l for l in sorted_leaves if l['timestamp'] >= join['timestamp']), None) # O(m) per join
...
join_is_included_in_duration = any(... for e in voice_channel_logs_duration) # O(k) per join
Replace with two bisects:
- bisect_left on the sorted leave-timestamps list to find the next leave
- bisect_right on a parallel sorted list of accepted-event start times to
cheaply detect overlapping joins (Discord voice events don't overlap
per user, so only the rightmost candidate needs checking)
Same shape of voice_channel_logs_duration coming out, downstream code
unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Voice-event aggregation was the dominant cost on the heavy package that just timed out at 15 min.
Two bisects replace the O(m) inner scan and the O(k) overlap check. Same output shape; downstream consumers unchanged.
For the package that just hit the cap: applying the 10GB memory bump from #68 should let it finish even on the old algorithm; this PR makes it not even close.