high-high generic: do not try forever

This commit is contained in:
gorhill 2015-03-01 20:26:33 -05:00
parent b6f1aa263c
commit bd0e07bef2
1 changed files with 15 additions and 6 deletions

View File

@ -93,7 +93,8 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
return; return;
} }
//var tStart = window.performance.now(); //var timer = window.performance || Date;
//var tStart = timer.now();
var queriedSelectors = {}; var queriedSelectors = {};
var injectedSelectors = {}; var injectedSelectors = {};
@ -154,7 +155,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
}; };
var otherRetrieveHandler = function(selectors) { var otherRetrieveHandler = function(selectors) {
//var tStart = window.performance.now(); //var tStart = timer.now();
//console.debug('µBlock> contextNodes = %o', contextNodes); //console.debug('µBlock> contextNodes = %o', contextNodes);
if ( selectors && selectors.highGenerics ) { if ( selectors && selectors.highGenerics ) {
highGenerics = selectors.highGenerics; highGenerics = selectors.highGenerics;
@ -193,7 +194,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
addStyleTag(hideSelectors); addStyleTag(hideSelectors);
} }
contextNodes.length = 0; contextNodes.length = 0;
//console.debug('%f: uBlock: CSS injection time', window.performance.now() - tStart); //console.debug('%f: uBlock: CSS injection time', timer.now() - tStart);
}; };
var retrieveHandler = firstRetrieveHandler; var retrieveHandler = firstRetrieveHandler;
@ -347,6 +348,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
// requests to process high-high generics into as few requests as possible. // requests to process high-high generics into as few requests as possible.
// The gain is *significant* on bloated pages. // The gain is *significant* on bloated pages.
var processHighHighGenericsMisses = 0;
var processHighHighGenericsTimer = null; var processHighHighGenericsTimer = null;
var processHighHighGenerics = function() { var processHighHighGenerics = function() {
@ -354,9 +356,16 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
if ( injectedSelectors.hasOwnProperty('{{highHighGenerics}}') ) { if ( injectedSelectors.hasOwnProperty('{{highHighGenerics}}') ) {
return; return;
} }
//var tStart = window.performance.now(); //var tStart = timer.now();
if ( document.querySelector(highGenerics.hideHigh) === null ) { if ( document.querySelector(highGenerics.hideHigh) === null ) {
//console.debug('%f: uBlock: high-high generic time', window.performance.now() - tStart); //console.debug('%f: high-high generic test time', timer.now() - tStart);
processHighHighGenericsMisses += 1;
// Too many misses for these nagging highly generic CSS rules,
// so we will just skip them from now on.
if ( processHighHighGenericsMisses >= 8 ) {
injectedSelectors['{{highHighGenerics}}'] = true;
console.debug('high-high generic: clearly not needed...');
}
return; return;
} }
injectedSelectors['{{highHighGenerics}}'] = true; injectedSelectors['{{highHighGenerics}}'] = true;
@ -444,7 +453,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
classesFromNodeList(document.querySelectorAll('[class]')); classesFromNodeList(document.querySelectorAll('[class]'));
retrieveGenericSelectors(); retrieveGenericSelectors();
//console.debug('%f: uBlock: survey time', window.performance.now() - tStart); //console.debug('%f: uBlock: survey time', timer.now() - tStart);
// Below this point is the code which takes care to observe changes in // Below this point is the code which takes care to observe changes in
// the page and to add if needed relevant CSS rules as a result of the // the page and to add if needed relevant CSS rules as a result of the