perf(ext/content): debounce MutationObserver scan() to 200ms (Plan C Phase 5)
DEV-C P2: SPA churn was re-running the full scan many times per second. Trailing-edge debounce coalesces bursts so scan() runs at most once per quiet 200ms window. No test harness exists for content/detector.ts on this branch; relies on manual verification on a real SPA page. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -93,9 +93,21 @@ setupFillListener();
|
|||||||
scan();
|
scan();
|
||||||
|
|
||||||
// Watch for DOM changes (SPA navigation, dynamically loaded forms).
|
// Watch for DOM changes (SPA navigation, dynamically loaded forms).
|
||||||
const observer = new MutationObserver(() => {
|
// Plan C Phase 5: SPA churn fires the MutationObserver many times per
|
||||||
scan();
|
// second. Trailing-edge debounce coalesces bursts so we run the full
|
||||||
});
|
// scan() at most once per quiet 200ms window.
|
||||||
|
const SCAN_DEBOUNCE_MS = 200;
|
||||||
|
let scanTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
|
function scheduleScan(): void {
|
||||||
|
if (scanTimer !== undefined) clearTimeout(scanTimer);
|
||||||
|
scanTimer = setTimeout(() => {
|
||||||
|
scanTimer = undefined;
|
||||||
|
scan();
|
||||||
|
}, SCAN_DEBOUNCE_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
const observer = new MutationObserver(scheduleScan);
|
||||||
|
|
||||||
observer.observe(document.body, {
|
observer.observe(document.body, {
|
||||||
childList: true,
|
childList: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user