Skip to content

Commit

Permalink
Do not exceed rate-limited calls to handlerBehaviorChanged()
Browse files Browse the repository at this point in the history
Related issue:
uBlockOrigin/uBlock-issues#3063

To prevent spurious performance warnings by chromium-based browsers.
  • Loading branch information
gorhill committed Jan 11, 2024
1 parent ba3a8d5 commit 63fe18a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/js/broadcast.js
Expand Up @@ -69,7 +69,19 @@ export function filteringBehaviorChanged(details = {}) {
}

filteringBehaviorChanged.throttle = vAPI.defer.create(( ) => {
const { history, max } = filteringBehaviorChanged;
const now = (Date.now() / 1000) | 0;
if ( history.length >= max ) {
if ( (now - history[0]) <= (10 * 60) ) { return; }
history.shift();
}
history.push(now);
vAPI.net.handlerBehaviorChanged();
});
filteringBehaviorChanged.history = [];
filteringBehaviorChanged.max = Math.min(
browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES - 1,
19
);

/******************************************************************************/

0 comments on commit 63fe18a

Please sign in to comment.