mirror of
https://github.com/vladmandic/automatic
synced 2026-08-26 06:30:44 +02:00
ui performance optimizations
Co-authored-by: Copilot <copilot@github.com> Signed-off-by: vladmandic <mandic00@live.com>
This commit is contained in:
+16
-8
@@ -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 });
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user