Skip to content

Fix #166: Replace pc_autosave O(N) iterator with a save queue#3414

Open
MrKeiKun wants to merge 2 commits into
HerculesWS:masterfrom
MrKeiKun:fix-166-pc_autosave-queue
Open

Fix #166: Replace pc_autosave O(N) iterator with a save queue#3414
MrKeiKun wants to merge 2 commits into
HerculesWS:masterfrom
MrKeiKun:fix-166-pc_autosave-queue

Conversation

@MrKeiKun

@MrKeiKun MrKeiKun commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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

MrKeiKun added 2 commits June 7, 2026 15:25
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).
@skyleo

skyleo commented Jun 7, 2026

Copy link
Copy Markdown
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.

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