mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 17:48:40 +00:00
[core] Optimize main loop with -O2
Add __attribute__((optimize("O2"))) to the main loop functions
(loop_task on ESP32, codegen loop() on other platforms) so GCC
inlines scheduler helpers and loop bookkeeping more aggressively.
Under -Os, GCC outlines small functions (Scheduler::call helpers,
millis conversions, etc.) that are called every loop iteration.
With -O2, these get inlined into the loop body, reducing call
overhead on the hottest code path in the firmware.
ESP32: loop_task grows from 303 to 416 bytes (+113 bytes).
ESP8266: no change (already fully inlined via ESPHOME_ALWAYS_INLINE).
This commit is contained in:
@@ -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();
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ void setup() {
|
||||
App.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void __attribute__((optimize("O2"))) loop() {
|
||||
App.loop();
|
||||
}
|
||||
""",
|
||||
|
||||
Reference in New Issue
Block a user