Skip to content

Conversation

@jlucaso1
Copy link

@jlucaso1 jlucaso1 commented Sep 15, 2025

I noticed that the server was using a surprising amount of CPU even when it was just sitting there idle with no players online.

I ran a quick 20-second benchmark (time timeout 20s ./bareiron) to see what was going on, check the results:

Before:

1.29s user 16.43s system 88% cpu 20.002 total

After:

0.00s user 0.00s system 0% cpu 20.002 total

As you can see, the total CPU usage was a whopping 88% just from the server doing nothing!

This is a experimental, i only tested on my machine (x86_64 arch linux) and wine, (both working great)

@p2r3
Copy link
Owner

p2r3 commented Sep 15, 2025

I'll note that, since this is a server for low-memory embedded platforms, and not really targeted towards desktop operating systems, a busy-loop is not nearly as big of an issue. This is why the contribution guidelines state to make an issue before a pull request, to discuss the necessity of the change.

I'll admit, I've only glanced at the diff, but that seems to be a lot of changes. Even removing some comments and adding a layer of nesting?

@jlucaso1
Copy link
Author

My apologies for not opening an issue first.
The main gains in this is the power consumption saving even for embedded platforms. The change is mostly structural wrapping the existing logic inside the new select()-based loop (this is the main reason about the amount of changes).
Agree about the comments removal, i'll add them back.

@jlucaso1 jlucaso1 force-pushed the perf/optimize-idle-loop branch from 52ed27e to e7106e2 Compare September 15, 2025 22:59
@fox3000foxy
Copy link
Contributor

Seems to be a pretty interesting concept tho

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.

3 participants