fix(ui): clamp deltaTime to 1ms in pose-renderer FPS calc (#519 Bug 2) (#610)

When two render frames land in the same performance.now() tick,
`currentTime - lastFrameTime === 0`, so `fps = 1000 / 0 = Infinity`,
and `averageFps = averageFps * 0.9 + Infinity * 0.1 = Infinity` poisons
the EMA forever after a single zero-dt tick. The UI then displays
"Infinity FPS" until reload.

Floor deltaTime at 1 ms before the division. That caps displayed FPS at
1000 (far above any real render rate so the cap is never observed in
practice) but keeps the EMA finite.

Reported in #519 ("Bug 2 — FPS shows Infinity") by @kapilsoni2013 on a
3-node ESP32-S3-WROOM multi-node setup with edge-tier 1 + 2.
This commit is contained in:
rUv
2026-05-17 19:16:00 -04:00
committed by GitHub
parent 1b155ad027
commit 6f5ac3aa5a
2 changed files with 10 additions and 3 deletions
+7 -3
View File
@@ -651,14 +651,18 @@ export class PoseRenderer {
this.performanceMetrics.frameCount++;
if (this.performanceMetrics.lastFrameTime > 0) {
const deltaTime = currentTime - this.performanceMetrics.lastFrameTime;
// Clamp to a minimum dt so consecutive frames within the same
// performance.now() tick don't yield Infinity (issue #519 Bug 2).
// 1 ms floor caps the displayed FPS at 1000 — far above any real
// render rate, but finite so the EMA stays well-defined.
const deltaTime = Math.max(currentTime - this.performanceMetrics.lastFrameTime, 1);
const fps = 1000 / deltaTime;
// Update average FPS using exponential moving average
if (this.performanceMetrics.averageFps === 0) {
this.performanceMetrics.averageFps = fps;
} else {
this.performanceMetrics.averageFps =
this.performanceMetrics.averageFps =
(this.performanceMetrics.averageFps * 0.9) + (fps * 0.1);
}
}