From 371e9a98709dc7129d4bebbcaf75b823c01c5819 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 25 Feb 2026 09:56:37 -0700 Subject: [PATCH] [web_server_idf] Use make_unique_for_overwrite for recv buffer The multipart receive buffer is immediately written by httpd_req_recv() before any read occurs, and only recv_len bytes (the amount actually received) are subsequently passed to the parser. Zero-initialization via make_unique is therefore unnecessary overhead. Switch to C++20 make_unique_for_overwrite which skips value-initialization for POD types, avoiding a redundant memset of the 1460-byte buffer on every multipart upload request. --- esphome/components/web_server_idf/web_server_idf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/web_server_idf/web_server_idf.cpp b/esphome/components/web_server_idf/web_server_idf.cpp index 4034a22586..f18570965b 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -921,7 +921,7 @@ esp_err_t AsyncWebServer::handle_multipart_upload_(httpd_req_t *r, const char *c }); // Use heap buffer - 1460 bytes is too large for the httpd task stack - auto buffer = std::make_unique(MULTIPART_CHUNK_SIZE); + auto buffer = std::make_unique_for_overwrite(MULTIPART_CHUNK_SIZE); size_t bytes_since_yield = 0; for (size_t remaining = r->content_len; remaining > 0;) {