This commit is contained in:
gorhill 2017-12-10 15:03:03 -05:00
parent fa048990ca
commit 958a7c20ed
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 23 additions and 34 deletions

View File

@ -246,7 +246,9 @@ vAPI.domWatcher = (function() {
} }
} }
if ( addedNodeLists.length !== 0 || removedNodes ) { if ( addedNodeLists.length !== 0 || removedNodes ) {
safeObserverHandlerTimer.start(1); safeObserverHandlerTimer.start(
addedNodeLists.length < 100 ? 1 : undefined
);
} }
//console.timeEnd('dom watcher/observer handler'); //console.timeEnd('dom watcher/observer handler');
}; };
@ -486,9 +488,10 @@ vAPI.DOMFilterer = (function() {
[ ':xpath', PSelectorXpathTask ] [ ':xpath', PSelectorXpathTask ]
]); ]);
} }
this.budget = 250; // I arbitrary picked a 1/4 second this.budget = 200; // I arbitrary picked a 1/5 second
this.raw = o.raw; this.raw = o.raw;
this.cost = 0; this.cost = 0;
this.lastAllowanceTime = 0;
this.selector = o.selector; this.selector = o.selector;
this.tasks = []; this.tasks = [];
var tasks = o.tasks; var tasks = o.tasks;
@ -533,8 +536,6 @@ vAPI.DOMFilterer = (function() {
this.addedSelectors = new Map(); this.addedSelectors = new Map();
this.addedNodes = false; this.addedNodes = false;
this.removedNodes = false; this.removedNodes = false;
this.addedNodesHandlerMissCount = 0;
this.currentResultset = new Set();
this.selectors = new Map(); this.selectors = new Map();
}; };
@ -587,8 +588,7 @@ vAPI.DOMFilterer = (function() {
this.addedSelectors.clear(); this.addedSelectors.clear();
} }
var currentResultset = this.currentResultset, var entry, nodes, i;
entry, nodes, i, node;
if ( this.addedSelectors.size !== 0 ) { if ( this.addedSelectors.size !== 0 ) {
//console.time('procedural selectors/filterset changed'); //console.time('procedural selectors/filterset changed');
@ -596,9 +596,7 @@ vAPI.DOMFilterer = (function() {
nodes = entry[1].exec(); nodes = entry[1].exec();
i = nodes.length; i = nodes.length;
while ( i-- ) { while ( i-- ) {
node = nodes[i]; this.domFilterer.hideNode(nodes[i]);
this.domFilterer.hideNode(node);
currentResultset.add(node);
} }
} }
this.addedSelectors.clear(); this.addedSelectors.clear();
@ -610,40 +608,31 @@ vAPI.DOMFilterer = (function() {
this.addedNodes = this.removedNodes = false; this.addedNodes = this.removedNodes = false;
var afterResultset = new Set(), var t0 = Date.now(),
t0 = Date.now(), t1, cost, pselector; t1, pselector, allowance;
for ( entry of this.selectors ) { for ( entry of this.selectors ) {
pselector = entry[1]; pselector = entry[1];
allowance = Math.floor((t0 - pselector.lastAllowanceTime) / 2000);
if ( allowance >= 1 ) {
pselector.budget += allowance * 50;
if ( pselector.budget > 200 ) { pselector.budget = 200; }
pselector.lastAllowanceTime = t0;
}
if ( pselector.budget <= 0 ) { continue; } if ( pselector.budget <= 0 ) { continue; }
nodes = pselector.exec(); nodes = pselector.exec();
t1 = Date.now();
pselector.budget += t0 - t1;
if ( pselector.budget < -500 ) {
console.log('uBO: disabling %s', pselector.raw);
pselector.budget = -0x7FFFFFFF;
}
t0 = t1;
i = nodes.length; i = nodes.length;
while ( i-- ) { while ( i-- ) {
node = nodes[i]; this.domFilterer.hideNode(nodes[i]);
this.domFilterer.hideNode(node);
afterResultset.add(node);
}
t1 = Date.now();
cost = t1 - t0;
t0 = t1;
if ( cost <= 8 ) { continue; }
pselector.budget -= cost;
if ( pselector.budget <= 0 ) {
console.log('disabling %s', pselector.raw);
} }
} }
if ( afterResultset.size !== currentResultset.size ) {
this.addedNodesHandlerMissCount = 0;
} else {
this.addedNodesHandlerMissCount += 1;
}
for ( node of currentResultset ) {
if ( afterResultset.has(node) === false ) {
this.domFilterer.unhideNode(node);
}
}
this.currentResultset = afterResultset;
//console.timeEnd('procedural selectors/dom layout changed'); //console.timeEnd('procedural selectors/dom layout changed');
}, },