Skip to content

Replace per-pokemon goroutines with pending queue#328

Closed
jfberry wants to merge 2 commits intomainfrom
feature/pokemon-pending-queue
Closed

Replace per-pokemon goroutines with pending queue#328
jfberry wants to merge 2 commits intomainfrom
feature/pokemon-pending-queue

Conversation

@jfberry
Copy link
Collaborator

@jfberry jfberry commented Jan 11, 2026

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?

decoder/main.go Outdated
}
}
}(wild.Data, int64(wild.Cell), wild.Timestamp)
// Add to pending queue instead of spawning a goroutine
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 🤣

encounterId := encounter.Pokemon.EncounterId

// Remove from pending queue - encounter arrived so no need for delayed wild update
if pokemonPendingQueue != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this should never be nilotherwise we would have forgotten to initialize it in the flow, right?

jfberry and others added 2 commits January 28, 2026 11:40
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>
@jfberry jfberry force-pushed the feature/pokemon-pending-queue branch from 1efe9ca to 22afd74 Compare January 28, 2026 11:40
@jfberry
Copy link
Collaborator Author

jfberry commented Jan 31, 2026

Included in #332

@jfberry jfberry closed this Jan 31, 2026
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