mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
d9c6b27cf2fbc2ae425cf9a186d6ac46af5b2bfa
Application::loop() used to, on every iteration of the inner component loop, OR each component's state into a local accumulator and then OR that into this->app_state_, finally overwriting this->app_state_ with the accumulator after the loop. That was ~5 instructions per component per loop iteration on the hot path, paying to rebuild state that's already kept current elsewhere. STATUS_LED_WARNING / STATUS_LED_ERROR are the only app_state_ bits anything reads. Component::set_status_flag_() already writes them to App.app_state_ directly the moment they're set, so any reader (status_led components, feed_wdt's LED re-dispatch) already sees them without the per-iter OR. The per-iter OR only ever re-set bits that were already there — pure dead code on the hot path. The clear path is handled by moving the work into status_clear_warning/error_slow_path_(): on a real set->clear transition the helpers walk App.components_ once to check if any other component still has the flag, and clear App.app_state_ if not. Clears are rare relative to loop iterations (a logged transition event), so O(N) per clear is far cheaper than O(N) per loop. Setup subtlety: Application::setup()'s slow-setup busy-wait forces STATUS_LED_WARNING on to blink the LED while a slow component initializes. A component clear during setup would prematurely wipe that forced bit, so status_clear_warning_slow_path_() gates its walk-and-clear behind APP_STATE_SETUP_COMPLETE (a free bit on app_state_ — zero RAM cost). Application::setup() reconciles the warning state once at the end and sets the flag. STATUS_LED_ERROR is never forced so its clear path always walks. Also fixes a pre-existing bug: the old per-iter accumulation only iterated looping_components_, so non-looping components' status bits would get clobbered by the end-of-loop 'app_state_ = new_app_state' overwrite. The walk-on-clear approach iterates components_ (all of them), so non-looping components are respected.
Description
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Readme
Multiple Licenses
546 MiB
Languages
C++
60.1%
Python
39.3%
C
0.3%
JavaScript
0.2%
