diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index 0a2a52f2e75..0e114d09338 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -84,7 +84,8 @@ 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 __attribute__((optimize("O2"))) loop_task(void *pv_params) { +void __attribute__((optimize("O2"))) // NOLINT(clang-diagnostic-unknown-attributes) +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 0ade4274feb..42178045164 100644 --- a/esphome/components/host/core.cpp +++ b/esphome/components/host/core.cpp @@ -77,7 +77,8 @@ uint32_t arch_get_cpu_freq_hz() { return 1000000000U; } void setup(); void loop(); -int main() { +int __attribute__((optimize("O2"))) // NOLINT(clang-diagnostic-unknown-attributes) +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 a3b0471ebcc..26832b3b217 100644 --- a/esphome/components/zephyr/core.cpp +++ b/esphome/components/zephyr/core.cpp @@ -95,7 +95,8 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame void setup(); void loop(); -int main() { +int __attribute__((optimize("O2"))) // NOLINT(clang-diagnostic-unknown-attributes) +main() { setup(); while (true) { loop(); diff --git a/esphome/core/application.h b/esphome/core/application.h index 374645d80a5..8d3168480f2 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -569,7 +569,10 @@ inline void ESPHOME_ALWAYS_INLINE Application::before_loop_tasks_(uint32_t loop_ this->in_loop_ = true; } -inline void ESPHOME_ALWAYS_INLINE Application::loop() { +// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) +inline void ESPHOME_ALWAYS_INLINE __attribute__((optimize("O2"))) Application::loop() { + uint8_t new_app_state = 0; + // Get the initial loop time at the start uint32_t last_op_end_time = millis(); diff --git a/tests/unit_tests/test_writer.py b/tests/unit_tests/test_writer.py index 1f5d4e75d9c..9c4a491e100 100644 --- a/tests/unit_tests/test_writer.py +++ b/tests/unit_tests/test_writer.py @@ -783,7 +783,8 @@ def test_write_cpp_creates_new_file( assert CPP_AUTO_GENERATE_END in written_content assert test_code in written_content assert "void setup()" in written_content - assert "void loop()" in written_content + assert 'optimize("O2")' in written_content + assert "loop()" in written_content assert "App.setup();" in written_content assert "App.loop();" in written_content