Fix FPS drops caused by brightness endpoint polling WLED device

The GET /devices/{id}/brightness endpoint was making an HTTP request to
the ESP32 over WiFi on every frontend poll (~3s), causing 150ms async
event loop jitter that froze the LED processing loop. Cache brightness
server-side after first fetch/set, add frontend dedup guard, reduce
get_device_info() frequency, and add processing loop timing diagnostics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 02:43:03 +03:00
parent b14da85f3b
commit 7c0c064453
4 changed files with 91 additions and 4 deletions

View File

@@ -288,7 +288,10 @@ export async function saveCardBrightness(deviceId, value) {
}
}
const _brightnessFetchInFlight = new Set();
export async function fetchDeviceBrightness(deviceId) {
if (_brightnessFetchInFlight.has(deviceId)) return;
_brightnessFetchInFlight.add(deviceId);
try {
const resp = await fetch(`${API_BASE}/devices/${deviceId}/brightness`, {
headers: getHeaders()
@@ -306,6 +309,8 @@ export async function fetchDeviceBrightness(deviceId) {
if (wrap) wrap.classList.remove('brightness-loading');
} catch (err) {
// Silently fail — device may be offline
} finally {
_brightnessFetchInFlight.delete(deviceId);
}
}