From cdfcb71f589d084a3fb0383372d7e88d9354ce48 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 16 Sep 2026 13:18:04 -0500 Subject: [PATCH] [display] Keep to_color() inlined in both draw_pixels_at loops With two call sites GCC at -Os stopped inlining to_color(), which cost a call and spills per pixel; flatten keeps it inlined, and the row loop now measures faster than before the change. --- esphome/components/display/display.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/display/display.cpp b/esphome/components/display/display.cpp index f5570818973..5ef70eead62 100644 --- a/esphome/components/display/display.cpp +++ b/esphome/components/display/display.cpp @@ -73,8 +73,11 @@ static inline ESPHOME_ALWAYS_INLINE uint32_t read_packed_pixel(const uint8_t *pt } } -void Display::draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorOrder order, - ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) { +// flatten keeps to_color() inlined in both loops; GCC at -Os stops inlining +// it once there are two call sites, which costs a call and spills per pixel. +__attribute__((flatten)) void Display::draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, + ColorOrder order, ColorBitness bitness, bool big_endian, + int x_offset, int y_offset, int x_pad) { const size_t line_stride = x_offset + w + x_pad; // length of each source line in pixels #ifdef USE_PSRAM // The source is row-major; when the display swaps the axes before writing,