perf: reduce daemon CPU usage by ~80% - #20
Conversation
9ecbb88 to
5c77753
Compare
|
Thank you! Test fail is extremely stale CI, which needs some TLC. I was about to suggest it would fail, but it beat me to it. House style across the board has been to rebuild libraries on top of our Python boilerplate. plasma is a bit of an outlier, though, so it hasn't been updated yet. Latest boilerplate is here: pimoroni/boilerplate-python#21 if you want to give it a shot (I don't expect you to, I'm just not sure when I'll get to it). Though it's probably a better use of time to just fix the CI breaks here rather than a full blown rebuild. |
|
Okay currently looking at repacking this, wish me luck! |
|
Just a - not - small change 💀 - #23 CI is passing, though. |
|
Great, I'll rebase my PRs once #23 is merged ! |
|
Right, sorted! |
- Skip redundant plasma.show() calls when color/brightness hasn't changed (solid colors now only update once instead of every frame) - Skip pattern re-rendering when the animation row hasn't advanced - Replace FIFO readline busy-wait (time.time() polling loop) with select.select() for proper blocking I/O - Cache loaded PNG patterns instead of re-parsing on every switch
Clearing the flag inside the set_all() branch meant the buffer was written but never latched to the hardware, so solid colours never displayed. Patterns were unaffected because that branch leaves the flag set.
7067c76 to
b3da94f
Compare
Tests cover: - FIFO.readline uses select.select for blocking I/O - Pattern caching avoids re-reading from disk - needs_update flag ensures show() only fires on state changes - Static color: show() called once, not every frame - Color/brightness changes trigger show() - FPS clamped to minimum 1
|
👋 this (and the others) should be ready now |
perf: reduce daemon CPU usage by ~80%
The plasma daemon was consuming up to 20% CPU on a Raspberry Pi even when displaying a static color. This PR addresses several performance issues:
Changes
plasma.show()is only called when the color or brightness actually changes, instead of being called every frame forevertime.time()polling loop withselect.select()for proper blocking I/O, eliminating CPU spin while waiting for commandsBenchmark
Tests
9 unit tests covering FIFO
select.select()usage, pattern caching,needs_updateflag behaviour (static color, colour change, brightness change), and FPS clamping. All pass alongside the existing test suite.