Replace per-pokemon goroutines with pending queue#328
Closed
Conversation
Fabio1988
reviewed
Jan 27, 2026
decoder/main.go
Outdated
| } | ||
| } | ||
| }(wild.Data, int64(wild.Cell), wild.Timestamp) | ||
| // Add to pending queue instead of spawning a goroutine |
Collaborator
There was a problem hiding this comment.
Can you pls change that comment? I know AI is always putting changes into the comments, but if I read this in the future I think about the goroutine, which is not visisble 🤣
Fabio1988
reviewed
Jan 27, 2026
| encounterId := encounter.Pokemon.EncounterId | ||
|
|
||
| // Remove from pending queue - encounter arrived so no need for delayed wild update | ||
| if pokemonPendingQueue != nil { |
Collaborator
There was a problem hiding this comment.
I assume this should never be nilotherwise we would have forgotten to initialize it in the flow, right?
Instead of spawning a goroutine for each wild pokemon that sleeps waiting for an encounter, use a single pending queue with a background sweeper. This reduces memory pressure and goroutine overhead under high load. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1efe9ca to
22afd74
Compare
Collaborator
Author
|
Included in #332 |
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.
Instead of spawning a goroutine for each wild pokemon that sleeps waiting for an encounter, use a single pending queue with a background sweeper. This reduces memory pressure and goroutine overhead under high load.
This only keeps the oldest pending pokemon in the queue (the expectation is that pokemon encounters usually overtake), however, since the source is the GMO we'll see it again.... this is probably the part of the logic I'm most concerned could be optimised, (eg could take the new pokemon and keep it in the queue instead) - but the danger is that new pokemon keep replacing old in the queue and it never gets "processed"
Thoughts?