From 1e156d46b6be25c2adf2be4cab8b1abee35a78a8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 31 Mar 2026 21:32:26 -1000 Subject: [PATCH] Fast path for get_and_reset_dropped_count to avoid critical section Plain read of aligned uint16_t is safe on ARM. Since drops are rare, almost every call returns 0 without entering a critical section. --- esphome/core/freertos_queue.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/core/freertos_queue.h b/esphome/core/freertos_queue.h index 5778c117973..0548ebfc710 100644 --- a/esphome/core/freertos_queue.h +++ b/esphome/core/freertos_queue.h @@ -59,6 +59,10 @@ template class FreeRTOSQueue { } uint16_t get_and_reset_dropped_count() { + // Fast path: plain read is safe for aligned uint16_t on ARM. + // Drops are rare so almost always returns 0 without entering a critical section. + if (this->dropped_count_ == 0) + return 0; portENTER_CRITICAL(); uint16_t count = this->dropped_count_; this->dropped_count_ = 0;