fix: reduce CPU usage, fix Vegas refresh, throttle high-FPS ticks#304
fix: reduce CPU usage, fix Vegas refresh, throttle high-FPS ticks#304ChuckBuilds merged 3 commits intomainfrom
Conversation
…-FPS plugin ticks Web UI Info plugin was causing 90%+ CPU on RPi4 due to frequent subprocess calls and re-rendering. Fixed by: trying socket-based IP detection first (zero subprocess overhead), caching AP mode checks with 60s TTL, reducing IP refresh from 30s to 5m, caching rendered display images, and loading fonts once at init. Vegas mode was not updating the display mid-cycle because hot_swap_content() reset the scroll position to 0 on every recomposition. Now saves and restores scroll position for mid-cycle updates. High-FPS display loop was calling _tick_plugin_updates() 125x/sec with no benefit. Added throttled wrapper that limits to 1 call/sec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReduced IP probe frequency and added short AP-mode caching in the WebUI plugin; display rendering now reuses a cached font and cached image; high‑FPS display loop throttles plugin-update ticks; Vegas pipeline preserves scroll state when hot-swapping mid-cycle. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
plugin-repos/web-ui-info/manager.py (1)
83-85: Use specific exceptions in new fallback paths.The new broad catches at Line 83 and Line 155 can hide concrete runtime issues and reduce debuggability.
♻️ Proposed refactor
- except Exception as e: + except (OSError, ValueError) as e: self.logger.debug(f"Could not load custom font: {e}, using default") return ImageFont.load_default()- except Exception: + except OSError: passAs per coding guidelines: "Catch specific exceptions, not bare
except:statements".Also applies to: 155-156
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugin-repos/web-ui-info/manager.py` around lines 83 - 85, The broad except Exception blocks around the custom font loading and the other fallback (the blocks that call ImageFont.load_default()) hide real errors; replace them with specific exception handlers: for the font-loading try/except around ImageFont.truetype(...) catch FileNotFoundError and OSError (or IOError) and log the error before falling back to ImageFont.load_default(), and for the image-related fallback catch PIL.UnidentifiedImageError and OSError (import UnidentifiedImageError from PIL) so only expected PIL/file errors are handled while letting unexpected exceptions surface.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/display_controller.py`:
- Around line 725-731: The throttled helper _tick_plugin_updates_throttled
currently hardcodes a 1.0s default which imposes a 1Hz cap and blocks plugins
that declare sub-second update_interval; change the function to avoid a fixed 1s
cap by (1) making the default min_interval non-blocking (e.g., 0.0) and treating
<=0 as “no global throttle” so plugin timing is driven by _tick_plugin_updates,
and (2) update the high-FPS caller that invokes _tick_plugin_updates_throttled
to pass an explicit min_interval when a global throttle is desired (or compute
and pass the minimum plugin-configured update_interval if you must enforce a
shared throttle). Update references: _tick_plugin_updates_throttled,
_tick_plugin_updates, and the _last_plugin_tick_time check to use the new
semantics so plugin-configured update_interval values are respected.
---
Nitpick comments:
In `@plugin-repos/web-ui-info/manager.py`:
- Around line 83-85: The broad except Exception blocks around the custom font
loading and the other fallback (the blocks that call ImageFont.load_default())
hide real errors; replace them with specific exception handlers: for the
font-loading try/except around ImageFont.truetype(...) catch FileNotFoundError
and OSError (or IOError) and log the error before falling back to
ImageFont.load_default(), and for the image-related fallback catch
PIL.UnidentifiedImageError and OSError (import UnidentifiedImageError from PIL)
so only expected PIL/file errors are handled while letting unexpected exceptions
surface.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4567f536-93a0-4cd3-999d-d70f227af93f
📒 Files selected for processing (3)
plugin-repos/web-ui-info/manager.pysrc/display_controller.pysrc/vegas_mode/render_pipeline.py
…tion handlers Make _tick_plugin_updates_throttled default to no-throttle (min_interval=0) so plugin-configured update_interval values are never silently capped. The high-FPS call site passes an explicit 1.0s interval. Narrow _load_font exception handler from bare Exception to FileNotFoundError | OSError so unexpected errors surface. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When content width changes during a mid-cycle recomposition (e.g., a plugin gains or loses items), blindly restoring the old scroll_position and total_distance_scrolled could overshoot the new total_scroll_width and trigger immediate false completion. Scale both values proportionally to the new width and clamp scroll_position to stay in bounds. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
hot_swap_content()now saves/restores scroll position during mid-cycle recomposition so the display updates without jumping back to position 0_tick_plugin_updates()was called 125x/sec in the scrolling loop with no benefit — now throttled to 1x/sec via_tick_plugin_updates_throttled()Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Performance Improvements
Bug Fixes