thecollabagepatch commited on
Commit
b285a5d
·
1 Parent(s): bcfe0f0

cleaning up logs in html demo

Browse files
Files changed (1) hide show
  1. magentaRT_rt_tester.html +33 -5
magentaRT_rt_tester.html CHANGED
@@ -243,6 +243,11 @@
243
  const queueEl = $("queue");
244
  const logEl = $("log");
245
 
 
 
 
 
 
246
  const rngMean = $("rngMean"), numMean = $("numMean");
247
  const rngC1 = $("rngC1"), numC1 = $("numC1");
248
  const rngC2 = $("rngC2"), numC2 = $("numC2");
@@ -307,12 +312,35 @@ function beginPlaybackFromPending() {
307
  let connected = false;
308
  let autoUpdateTimer = null;
309
 
 
 
 
 
310
  function log(msg, cls) {
311
- const line = document.createElement("div");
312
- line.textContent = msg;
313
- if (cls) line.className = cls;
314
- logEl.appendChild(line);
315
- logEl.scrollTop = logEl.scrollHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  }
317
 
318
  function setStatus(txt) {
 
243
  const queueEl = $("queue");
244
  const logEl = $("log");
245
 
246
+ // --- Ring buffer logging (batched with rAF) ---
247
+ const LOG_MAX = 200; // keep last N lines
248
+ let logBuf = []; // [{msg, cls}]
249
+ let logFlushScheduled = false;
250
+
251
  const rngMean = $("rngMean"), numMean = $("numMean");
252
  const rngC1 = $("rngC1"), numC1 = $("numC1");
253
  const rngC2 = $("rngC2"), numC2 = $("numC2");
 
312
  let connected = false;
313
  let autoUpdateTimer = null;
314
 
315
+ /**
316
+ * Push a line into the log ring and schedule a single repaint via rAF.
317
+ * This avoids per-append DOM work and forced reflow during capture.
318
+ */
319
  function log(msg, cls) {
320
+ logBuf.push({ msg: String(msg), cls: cls || "" });
321
+ // Trim oldest if we exceed capacity
322
+ if (logBuf.length > LOG_MAX) {
323
+ logBuf.splice(0, logBuf.length - LOG_MAX);
324
+ }
325
+ if (!logFlushScheduled) {
326
+ logFlushScheduled = true;
327
+ requestAnimationFrame(flushLog);
328
+ }
329
+ }
330
+ function flushLog() {
331
+ logFlushScheduled = false;
332
+ // If user is already at bottom, keep them there after the flush
333
+ const atBottom = (logEl.scrollTop + logEl.clientHeight + 4) >= logEl.scrollHeight;
334
+ // Rebuild using a fragment (fast for ~200 nodes)
335
+ const frag = document.createDocumentFragment();
336
+ for (const {msg, cls} of logBuf) {
337
+ const div = document.createElement("div");
338
+ if (cls) div.className = cls;
339
+ div.textContent = msg;
340
+ frag.appendChild(div);
341
+ }
342
+ logEl.replaceChildren(frag);
343
+ if (atBottom) logEl.scrollTop = logEl.scrollHeight;
344
  }
345
 
346
  function setStatus(txt) {