diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index add50dcf4d..1fa51f1d9e 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -65,7 +65,7 @@ static StaticTask_t loop_task_tcb; // NOLINT(cppcoreguidelines-avoid-non- static StackType_t loop_task_stack[ESPHOME_LOOP_TASK_STACK_SIZE]; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -void loop_task(void *pv_params) { +void __attribute__((optimize("O2"))) loop_task(void *pv_params) { setup(); while (true) { App.loop(); diff --git a/esphome/components/host/core.cpp b/esphome/components/host/core.cpp index 0ade4274fe..596b46305f 100644 --- a/esphome/components/host/core.cpp +++ b/esphome/components/host/core.cpp @@ -77,7 +77,7 @@ uint32_t arch_get_cpu_freq_hz() { return 1000000000U; } void setup(); void loop(); -int main() { +int __attribute__((optimize("O2"))) main() { // Install signal handlers for graceful shutdown (flushes preferences to disk) std::signal(SIGINT, signal_handler); std::signal(SIGTERM, signal_handler); diff --git a/esphome/components/zephyr/core.cpp b/esphome/components/zephyr/core.cpp index a3b0471ebc..84dee374f5 100644 --- a/esphome/components/zephyr/core.cpp +++ b/esphome/components/zephyr/core.cpp @@ -95,7 +95,7 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame void setup(); void loop(); -int main() { +int __attribute__((optimize("O2"))) main() { setup(); while (true) { loop(); diff --git a/esphome/core/application.h b/esphome/core/application.h index 6b2969b490..5b68146b2d 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -837,7 +837,7 @@ inline void ESPHOME_ALWAYS_INLINE Application::before_loop_tasks_(uint32_t loop_ this->in_loop_ = true; } -inline void ESPHOME_ALWAYS_INLINE Application::loop() { +inline void ESPHOME_ALWAYS_INLINE __attribute__((optimize("O2"))) Application::loop() { uint8_t new_app_state = 0; // Get the initial loop time at the start diff --git a/esphome/writer.py b/esphome/writer.py index 06a2230118..c2e0d08fa4 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -45,7 +45,7 @@ void setup() { App.setup(); } -void loop() { +void __attribute__((optimize("O2"))) loop() { App.loop(); } """,