perf: reduce background CPU churn and battery usage. - #859
Merged
mpfaffenberger merged 1 commit intoAug 27, 2026
Conversation
Also added some blank lines to enhance readability.
StarsExpress
marked this pull request as ready for review
August 23, 2026 20:18
mpfaffenberger
approved these changes
Aug 27, 2026
mpfaffenberger
approved these changes
Aug 27, 2026
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.
Refs issue #438 to decrease busy-wait polling in
code_puppy/messaging/bus.py: get_message(), get_command().PR #859's choice
PR #859 implements the latter option — back off sleep interval when idle — as an alleviation for background CPU churn and battery usage.
Full fix to bridge
code_puppy/tools/command_runner.py's backgroundthreading.Thread— used for streaming subprocess output — into the event loop vialoop.call_soon_threadsafeis a larger and thus separate follow-up, since a straight swap toasyncio.Queuewould break these cross-thread writes.Alleviation implementations
code_puppy/messaging/bus.py: MessageBusnow has a shared static method forget_message()andget_command():Idle CPU wakeups reduction
Tradeoffs
After empirically measuring for a message arriving after 0.4s of idle,
additional latencyintroduced by this backoff is ~57.8ms.Theoretical worst case is bounded by 0.1s backoff cap itself, since delay resets to 0.01s immediately after each successful read.
Additional adjustments
Inside
code_puppy/messaging/bus.py, I added some blank lines to visually separate code chunks for better readability.