mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-26 02:27:11 +00:00
perf(extension): cut target selection from ~20s to under 3s
Selecting an anime tab took long enough that it read as broken. Measured against the two anime fixtures, the cost was three multiplying blocks, none of which was doing useful work. The visibility handshake ran on every page with more than one frame, including pages where no frame had a video at all. Its only purpose is to rank and exclude video candidates, so with nothing to rank it was several seconds of pure waiting per attempt. It is now skipped unless a candidate exists. Its pass count was fixed at four, the worst-case same-origin nesting depth. It now scales to the depth actually observed, which is two on these players, and each surplus pass was a full round trip across every frame. The retry budget was spent waiting for a video that no frame had. Retrying cannot conjure one, and the injected monitor promotes the real player within a fraction of a second of it appearing, so the loop stops instead — and only retries when the sweep itself came back thin, which is the case a second pass can actually fix. Both probe timeouts were also far too generous. inspectMediaFrame and the monitor injection are synchronous DOM work: a live frame answers in tens of milliseconds and anything slower is a frame being torn down, which is exactly what an ad slot is. 2000ms down to 750ms; a frame dropped there is re-probed on the next attempt and reports itself through its monitor anyway. Measured, calm page then heavy ad churn: selection 2.5s / 2.6s (was 2.5s / 7.2s, and ~12s before this series) promotion 0.34s / 2.7s (was 0.35s / 6.4s, and ~15s before this series) The remaining time is the injection chain itself, not discovery. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2510,7 +2510,7 @@ async function injectMediaFrameMonitors(tabId, contentTarget) {
|
||||
await executeScriptWithTimeout({
|
||||
target,
|
||||
files: ['media-frame-monitor.js']
|
||||
}, 2000);
|
||||
}, 750);
|
||||
injectedCount++;
|
||||
} catch {
|
||||
// One denied widget frame must not block the selected player.
|
||||
@@ -2528,7 +2528,7 @@ async function injectMediaFrameMonitors(tabId, contentTarget) {
|
||||
await executeScriptWithTimeout({
|
||||
target,
|
||||
files: ['media-frame-monitor.js']
|
||||
}, 2000);
|
||||
}, 750);
|
||||
injectedCount++;
|
||||
} catch {
|
||||
// Main injection below reports a real selected-target failure.
|
||||
|
||||
Reference in New Issue
Block a user