diff --git a/src/js/benchmarks.js b/src/js/benchmarks.js index c41024698..8603b8737 100644 --- a/src/js/benchmarks.js +++ b/src/js/benchmarks.js @@ -166,11 +166,11 @@ export async function benchmarkStaticNetFiltering(options = {}) { let allowCount = 0; let redirectCount = 0; let removeparamCount = 0; + let urlskipCount = 0; let cspCount = 0; let permissionsCount = 0; let replaceCount = 0; - for ( let i = 0; i < requests.length; i++ ) { - const request = requests[i]; + for ( const request of requests ) { fctxt.setURL(request.url); if ( fctxt.getIPAddress() === '' ) { fctxt.setIPAddress('93.184.215.14\n2606:2800:21f:cb07:6820:80da:af6b:8b2c'); @@ -186,12 +186,15 @@ export async function benchmarkStaticNetFiltering(options = {}) { if ( sfne.transformRequest(fctxt) ) { redirectCount += 1; } - if ( fctxt.redirectURL !== undefined && sfne.hasQuery(fctxt) ) { - if ( sfne.filterQuery(fctxt, 'removeparam') ) { + if ( sfne.hasQuery(fctxt) ) { + if ( sfne.filterQuery(fctxt) ) { removeparamCount += 1; } } - if ( fctxt.type === 'main_frame' || fctxt.type === 'sub_frame' ) { + if ( sfne.urlSkip(fctxt) ) { + urlskipCount += 1; + } + if ( fctxt.isDocument() ) { if ( sfne.matchAndFetchModifiers(fctxt, 'csp') ) { cspCount += 1; } @@ -207,9 +210,9 @@ export async function benchmarkStaticNetFiltering(options = {}) { if ( sfne.redirectRequest(redirectEngine, fctxt) ) { redirectCount += 1; } - } - if ( fctxt.type === 'main_frame' ) { - sfne.matchAndFetchModifiers(fctxt, 'urlskip'); + if ( fctxt.isRootDocument() && sfne.urlSkip(fctxt) ) { + urlskipCount += 1; + } } } const t1 = performance.now(); @@ -224,6 +227,7 @@ export async function benchmarkStaticNetFiltering(options = {}) { `\tUnblocked: ${allowCount}`, `\tredirect=: ${redirectCount}`, `\tremoveparam=: ${removeparamCount}`, + `\turlskip=: ${urlskipCount}`, `\tcsp=: ${cspCount}`, `\tpermissions=: ${permissionsCount}`, `\treplace=: ${replaceCount}`, diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 1b94b1fef..e23f0950e 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -942,6 +942,9 @@ const PageStore = class { if ( staticNetFilteringEngine.hasQuery(fctxt) ) { staticNetFilteringEngine.filterQuery(fctxt, directives); } + if ( this.urlSkippableResources.has(fctxt.itype) ) { + staticNetFilteringEngine.urlSkip(fctxt, directives); + } if ( directives.length === 0 ) { return; } if ( logger.enabled !== true ) { return; } fctxt.pushFilters(directives.map(a => a.logData())); @@ -1132,23 +1135,31 @@ const PageStore = class { response.blockedResources = this.netFilteringCache.lookupAllBlocked(fctxt.getDocHostname()); } + + cacheableResults = new Set([ + µb.FilteringContext.SUB_FRAME + ]); + + collapsibleResources = new Set([ + µb.FilteringContext.IMAGE, + µb.FilteringContext.MEDIA, + µb.FilteringContext.OBJECT, + µb.FilteringContext.SUB_FRAME, + ]); + + urlSkippableResources = new Set([ + µb.FilteringContext.IMAGE, + µb.FilteringContext.MAIN_FRAME, + µb.FilteringContext.MEDIA, + µb.FilteringContext.OBJECT, + µb.FilteringContext.SUB_FRAME, + ]); + + // To mitigate memory churning + static junkyard = []; + static junkyardMax = 10; }; -PageStore.prototype.cacheableResults = new Set([ - µb.FilteringContext.SUB_FRAME, -]); - -PageStore.prototype.collapsibleResources = new Set([ - µb.FilteringContext.IMAGE, - µb.FilteringContext.MEDIA, - µb.FilteringContext.OBJECT, - µb.FilteringContext.SUB_FRAME, -]); - -// To mitigate memory churning -PageStore.junkyard = []; -PageStore.junkyardMax = 10; - /******************************************************************************/ export { PageStore }; diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 73218aba5..0fb6dc5b8 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5449,9 +5449,9 @@ StaticNetFilteringEngine.prototype.urlSkip = function(fctxt, out = []) { return out; }; -function urlSkip(directive, urlin, steps) { +function urlSkip(directive, url, steps) { try { - let urlout = urlin; + let urlout = url; for ( const step of steps ) { const urlin = urlout; const c0 = step.charCodeAt(0); diff --git a/src/js/traffic.js b/src/js/traffic.js index 5de002797..eab93be74 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -196,8 +196,9 @@ const onBeforeRootFrameRequest = function(fctxt) { if ( trusted === false && pageStore !== null ) { if ( result !== 1 ) { pageStore.redirectNonBlockedRequest(fctxt); + } else { + pageStore.skipMainDocument(fctxt); } - pageStore.skipMainDocument(fctxt); } if ( logger.enabled ) {