Fix #166: Replace pc_autosave O(N) iterator with a save queue#3414
Open
MrKeiKun wants to merge 2 commits into
Open
Fix #166: Replace pc_autosave O(N) iterator with a save queue#3414MrKeiKun wants to merge 2 commits into
MrKeiKun wants to merge 2 commits into
Conversation
The previous implementation iterated all connected players on every autosave tick (O(N)) to find the next one to save, and kept the timer running even with no players online. This replaces that with a FIFO queue of bl.ids (O(1) lookup via map->id2sd). Players are enqueued on login and dequeued on logout. The timer is started by the first login and stops when the queue empties, eliminating idle wakeups on an empty server. The interval is now computed as autosave_interval / queue_length, preserving the original intent of distributing saves evenly across the configured window.
pc_autosave_start used queue_length+1 while pc_autosave used queue_length, making the first save cycle shorter than autosave_interval. Both now divide by queue_length directly (safe since the queue is always non-empty when pc_autosave_start is called).
Contributor
|
Please don't merge this yet @hemagx . It's a very nice idea, but there is a very similar nice idea already tested, adressing more edge cases and tested by time and a decent amount of players on Arcadia Online, which I will share and KeiKun and me will compare our solutions. Or rather we already are comparing as this PR came up due to a conversation about this optimization. |
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.
The previous implementation iterated all connected players on every autosave tick (O(N)) to find the next one to save, and kept the timer running even with no players online.
This replaces that with a FIFO queue of bl.ids (O(1) lookup via map->id2sd). Players are enqueued on login and dequeued on logout. The timer is started by the first login and stops when the queue empties, eliminating idle wakeups on an empty server.
The interval is now computed as autosave_interval / queue_length, preserving the original intent of distributing saves evenly across the configured window.
Pull Request Prelude
Changes Proposed
Issues addressed: #166