From 21a452333eb83135b1596430ce4a4be28136b7e8 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 21 Dec 2025 23:11:15 +0100 Subject: [PATCH] setRealtimePixel speedup cache strip.getMainSegment(), strip.getLengthTotal()), seg.length() instead of re-calculating them for each pixel --- wled00/udp.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 6b01702f..1eef841a 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -150,6 +150,11 @@ void notify(byte callMode, bool followUp) notificationCount = followUp ? notificationCount + 1 : 0; } +// WLEDMM cache current main segment: updated in realtimeLock, reset in exitRealtime, used in setRealTimePixel +static Segment* theMainSeg = nullptr; +static int theMainSegLength = 0; +static int theStripLength = 0; + void realtimeLock(uint32_t timeoutMs, byte md) { if (!realtimeMode && !realtimeOverride) { @@ -197,6 +202,12 @@ void realtimeLock(uint32_t timeoutMs, byte md) } realtimeMode = md; + // WLEDMM cache current "main segment" + Segment& mainSegRef = strip.getMainSegment(); + theMainSeg = &mainSegRef; //convert from reference to pointer + theMainSegLength = realtimeOverride ? 0 : theMainSeg->length(); + theStripLength = realtimeOverride ? 0 : strip.getLengthTotal(); + if (realtimeOverride) return; if (arlsForceMaxBri) strip.setBrightness(scaledBri(255), true); if (briT > 0 && md == REALTIME_MODE_GENERIC) strip.show(); @@ -216,6 +227,10 @@ void exitRealtime() { } else { strip.show(); // possible fix for #3589 } + // WLEDMM invalide cached main segment pointer and length + theMainSeg = nullptr; + theMainSegLength = 0; + theStripLength = 0; busses.invalidateCache(false); // WLEDMM USER_PRINTLN(F("exitRealtime() realtime mode ended.")); updateInterfaces(CALL_MODE_WS_SEND); @@ -650,8 +665,8 @@ void handleNotifications() void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) { - uint16_t pix = i + arlsOffset; - if (pix < strip.getLengthTotal()) { + int pix = i + arlsOffset; + if (pix < theStripLength) { // WLEDMM use cached length if (!arlsDisableGammaCorrection && gammaCorrectCol) { r = gamma8(r); g = gamma8(g); @@ -659,8 +674,8 @@ void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) w = gamma8(w); } if (useMainSegmentOnly) { - Segment &seg = strip.getMainSegment(); - if (pixsetPixelColor(pix, r, g, b, w); // WLEDMM used cached main segment } else { strip.setPixelColor(pix, r, g, b, w); }