From 6b7c52799d44bf361208a7dd8698570e28ef1f8e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 7 Feb 2026 00:02:10 +0100 Subject: [PATCH] [nextion] Batch UART reads to reduce loop overhead --- esphome/components/nextion/nextion.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index fd6ce0a24b2..f3a24de30ad 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -397,11 +397,21 @@ bool Nextion::remove_from_q_(bool report_empty) { } void Nextion::process_serial_() { - uint8_t d; + int avail = this->available(); + if (avail == 0) { + return; + } - while (this->available()) { - read_byte(&d); - this->command_data_ += d; + // Read all available bytes in batches to reduce UART call overhead. + uint8_t buf[64]; + while (avail > 0) { + size_t to_read = std::min(static_cast(avail), sizeof(buf)); + if (!this->read_array(buf, to_read)) { + break; + } + avail -= to_read; + + this->command_data_.append(reinterpret_cast(buf), to_read); } } // nextion.tech/instruction-set/