ui performance optimizations

Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: vladmandic <mandic00@live.com>
This commit is contained in:
vladmandic
2026-04-19 16:14:19 +02:00
parent 271a3421d6
commit 6128e0f84b
9 changed files with 252 additions and 59 deletions
+16 -8
View File
@@ -67,7 +67,10 @@ function executeCallbacks(queue, arg) {
for (const callback of queue) {
if (!callback) continue;
try {
const t0 = performance.now();
callback(arg);
const t1 = performance.now();
if (t1 - t0 > 250) log('callbackSlow', callback.name || callback, `time=${Math.round(t1 - t0)}`);
} catch (e) {
error(`executeCallbacks: ${callback} ${e}`);
}
@@ -83,17 +86,21 @@ function scheduleAfterUiUpdateCallbacks() {
let executedOnLoaded = false;
const ignoreElements = ['logMonitorData', 'logWarnings', 'logErrors', 'tooltip-container', 'logger'];
const ignoreElementsSet = new Set(ignoreElements);
const ignoreClasses = ['wrap'];
let mutationTimer = null;
let validMutations = [];
async function mutationCallback(mutations) {
let newMutations = mutations;
if (newMutations.length > 0) newMutations = newMutations.filter((m) => m.target.nodeName !== 'LABEL');
if (newMutations.length > 0) newMutations = newMutations.filter((m) => ignoreElements.indexOf(m.target.id) === -1);
if (newMutations.length > 0) newMutations = newMutations.filter((m) => m.target.id !== 'logWarnings' && m.target.id !== 'logErrors');
if (newMutations.length > 0) newMutations = newMutations.filter((m) => !m.target.classList?.contains('wrap'));
if (newMutations.length > 0) validMutations = validMutations.concat(newMutations);
if (mutations.length <= 0) return;
for (const mutation of mutations) {
const target = mutation.target;
if (target.nodeName === 'LABEL') continue;
if (ignoreElementsSet.has(target.id)) continue;
if (target.classList?.contains(ignoreClasses[0])) continue;
validMutations.push(mutation);
}
if (validMutations.length < 1) return;
if (mutationTimer) clearTimeout(mutationTimer);
@@ -113,12 +120,13 @@ async function mutationCallback(mutations) {
}
validMutations = [];
mutationTimer = null;
}, 50);
}, 100);
}
document.addEventListener('DOMContentLoaded', () => {
log('DOMContentLoaded');
const mutationObserver = new MutationObserver(mutationCallback);
mutationObserver.observe(gradioApp(), { childList: true, subtree: true });
mutationObserver.observe(gradioApp(), { childList: true, subtree: true, attributes: false });
});
/**