mirror of
https://github.com/CNCKitchen/stlTexturizer.git
synced 2026-04-07 22:11:32 +00:00
perf: time-based yield reduces background tab overhead by ~95%
Replace fixed-interval yields (every 4096 iterations) with time-based yields (every ~100ms of wall time). In foreground tabs this means ~10 yields per second instead of ~50-200, with identical UI responsiveness. In background tabs where setTimeout(0) is throttled to ~1s, this reduces overhead from ~200 wasted seconds to ~10 — the export runs nearly as fast in the background as in the foreground. Addresses #2 (background tab resource allocation).
This commit is contained in:
@@ -84,6 +84,7 @@ export async function subdivide(geometry, maxEdgeLength, onProgress, faceWeights
|
||||
|
||||
const newTriCount = newIndices.length / 3;
|
||||
if (onProgress) onProgress(Math.min(0.95, (iter + 1) / maxIterations), newTriCount, longestEdge);
|
||||
// Yield once per subdivision pass (not per iteration) — keeps background tabs fast
|
||||
await new Promise(r => setTimeout(r, 0));
|
||||
if (!changed || safetyCapHit) break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user