Skip to content

Add passive adaptive entity state throttling on slow devices - #56421

Draft
MindFreeze wants to merge 1 commit into
devfrom
adaptive-entity-state-throttling
Draft

MindFreeze wants to merge 1 commit into
devfrom
adaptive-entity-state-throttling

Conversation

@MindFreeze

Copy link
Copy Markdown
Member

Breaking change

Proposed change

Wires up throttleMs and flushEntityStates from home-assistant/home-assistant-js-websocket#824 using passive, cross-browser self-measurement (EntityStateThrottler):

  • Adaptive duty-cycle throttling: Measures actual state-update cost (sync + Lit microtasks + layout/paint via a split MessageChannel + rAF → MessageChannel probe; zero timers when idle, ~0.003–0.018 ms overhead per publish) and scales the throttle interval up to 1,000 ms to keep state updates within a ~12% main-thread budget. Fast devices on light dashboards stay at 0 ms (per-frame microtask batching).
  • User-action fast-path: Calling hass.callService() drops the throttle interval to 0 ms for 2 s so toggles and controls still update immediately.
  • Hidden-tab pause: Returns Infinity while document.hidden (when suspendWhenHidden is enabled) and flushes immediately via flushEntityStates(conn) on visibility return (visibilitychange + whenDocumentVisible).

Depends on home-assistant/home-assistant-js-websocket#824. Needs a release of home-assistant-js-websocket and a version bump here before it can be merged (typecheck/build fail until then).

Benchmarks (Chromium 158, 5,000 entities, busy Lovelace dashboard, 30 WS frames/sec × 15 s)

CPU / Mode Publishes Total CPU % rAF FPS Jank (>50 ms) LoAFs (Block ms) User Toggle Med / Max
6× CPU — Per-frame (throttleMs: 0) 458 99.5% 18.6 148 134 (1,665 ms) 18.5 / 22.2 ms
6× CPU — Adaptive + User-Action Fast-Path (auto ~380 ms) 47 46.3% 57.5 0 0 (0 ms) 24.4 / 26.0 ms
6× CPU — Hidden tab (Infinity) → Resume flush 1 1.2% N/A 0 0 (0 ms) Resume: 65.8 ms
1× CPU — Per-frame (throttleMs: 0) 458 — 60.1 0 0 3.7 / 4.6 ms
1× CPU — Adaptive + User-Action Fast-Path 123 — 60.1 0 0 6.7 / 7.9 ms

Screenshots

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the perfect PR recommendations
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

To help with the load of incoming pull requests:

@home-assistant

home-assistant Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

👋 Hi! Thanks for contributing to Home Assistant.

This is your PR dashboard which flags anything you need to address before your PR can be reviewed. Once everything is green, you can press the 'Ready for review' button at the bottom of the page to notify reviewers to take a look.

More information about this dashboard

This dashboard automatically updates on every change to this PR and reevaluates the rules as you go. Until everything has been addressed, the bot will keep the PR in draft.

Skip a check that doesn't apply

If you think a check doesn't apply to your PR (or the rule is bugged), comment @home-assistant ignore "<check name>" "<reason>". The check name as shown in the table above. This will mark the check as ignored and let you put your PR in 'Ready for review'; @home-assistant unignore "<check name>" restores the rule.

Bot commands

Reply with @home-assistant <command>. Several commands can be stacked, one per line:

  • update — Re-runs the bot's checks on the issue or pull request.
  • ignore — Waives a dashboard check: ignore "<check name>" "<reason>". (author) — e.g. @home-assistant ignore "Merge conflicts" "Broken rule, no merge conflicts present"
  • unignore — Restores a waived dashboard check: unignore "<check name>". (author) — e.g. @home-assistant unignore "Merge conflicts"

Checks

✨ Everything's in order!

1 check passed (2 skipped)
Status Check Details
✅ CLA Everyone involved has signed the CLA.
➖ Belongs together No pull requests listed.
➖ Blocking: wait for backend wait for backend label not set — nothing to block.

@MindFreeze MindFreeze added the Performance Affects the performance of the UI label Dec 3, 2026
@MindFreeze
MindFreeze force-pushed the adaptive-entity-state-throttling branch from fa8bd45 to 5cc5f64 Compare December 4, 2026 08:13
@github-actions github-actions Bot added the Tests: Unit Related to Vitest unit tests label Dec 4, 2026
@bramkragten

bramkragten commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

I'm not sure the measuring is worth it/needed, could we not throttle it always for every device with a sane 100-250ms value? That would make it a lot simpler. We could even split the subscription in 2, 1 throttled one, that contains all the entities, and 1 unthrottled one, that contains the entities that are used explicitly?

That makes sure that built-in cards are always updated quick, and custom cards that don't adapt will keep work, but a bit throttled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Affects the performance of the UI Tests: Unit Related to Vitest unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants