mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 11:22:38 +01:00
Fine tune built-in benchmark
Additionally, add a button in the About pane to launch benchmark sessions. The button will be available only when advanced setting `benchmarkDatasetURL` is set and pointing to a valid dataset.
This commit is contained in:
parent
e5b932335c
commit
4059a92838
@ -40,6 +40,11 @@
|
|||||||
<div class="li"><span><a href="https://fontawesome.com/" target="_blank">FontAwesome font family</a> by <a href="https://github.com/davegandy">Dave Gandy</a></span></div>
|
<div class="li"><span><a href="https://fontawesome.com/" target="_blank">FontAwesome font family</a> by <a href="https://github.com/davegandy">Dave Gandy</a></span></div>
|
||||||
<div class="li"><span><a href="https://github.com/Swatinem/diff" target="_blank">An implementation of Myers' diff algorithm</a> by <a href="https://github.com/Swatinem">Arpad Borsos</a></span></div>
|
<div class="li"><span><a href="https://github.com/Swatinem/diff" target="_blank">An implementation of Myers' diff algorithm</a> by <a href="https://github.com/Swatinem">Arpad Borsos</a></span></div>
|
||||||
</div>
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div id="dev">
|
||||||
|
<button id="sfneBenchmark">Benchmark static filtering engine</button>
|
||||||
|
<div id="sfneBenchmarkResult"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="js/vapi.js"></script>
|
<script src="js/vapi.js"></script>
|
||||||
|
@ -9,3 +9,16 @@ body {
|
|||||||
.entry {
|
.entry {
|
||||||
margin: 0.5em 0;
|
margin: 0.5em 0;
|
||||||
}
|
}
|
||||||
|
#dev {
|
||||||
|
align-items: flex-start;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#dev.enabled {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
#dev > * {
|
||||||
|
margin-inline-end: 1em;
|
||||||
|
}
|
||||||
|
#dev > div {
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
@ -36,5 +36,20 @@
|
|||||||
const appData = await vAPI.messaging.send('dashboard', {
|
const appData = await vAPI.messaging.send('dashboard', {
|
||||||
what: 'getAppData',
|
what: 'getAppData',
|
||||||
});
|
});
|
||||||
|
|
||||||
uDom('#aboutNameVer').text(appData.name + ' v' + appData.version);
|
uDom('#aboutNameVer').text(appData.name + ' v' + appData.version);
|
||||||
|
|
||||||
|
if ( appData.canBenchmark !== true ) { return; }
|
||||||
|
|
||||||
|
document.getElementById('dev').classList.add('enabled');
|
||||||
|
|
||||||
|
const sfneBenchmark = async ( ) => {
|
||||||
|
const result = await vAPI.messaging.send('dashboard', {
|
||||||
|
what: 'sfneBenchmark',
|
||||||
|
});
|
||||||
|
document.getElementById('sfneBenchmarkResult').textContent = result;
|
||||||
|
};
|
||||||
|
document.getElementById('sfneBenchmark').addEventListener('click', ( ) => {
|
||||||
|
sfneBenchmark();
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -1084,8 +1084,10 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
|
|||||||
if ( injectedHideFilters.length !== 0 ) {
|
if ( injectedHideFilters.length !== 0 ) {
|
||||||
out.injectedHideFilters = injectedHideFilters.join(',\n');
|
out.injectedHideFilters = injectedHideFilters.join(',\n');
|
||||||
details.code = out.injectedHideFilters + '\n{display:none!important;}';
|
details.code = out.injectedHideFilters + '\n{display:none!important;}';
|
||||||
|
if ( options.dontInject !== true ) {
|
||||||
vAPI.tabs.insertCSS(request.tabId, details);
|
vAPI.tabs.insertCSS(request.tabId, details);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CSS selectors for collapsible blocked elements
|
// CSS selectors for collapsible blocked elements
|
||||||
if ( cacheEntry ) {
|
if ( cacheEntry ) {
|
||||||
@ -1093,9 +1095,11 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
|
|||||||
cacheEntry.retrieve('net', networkFilters);
|
cacheEntry.retrieve('net', networkFilters);
|
||||||
if ( networkFilters.length !== 0 ) {
|
if ( networkFilters.length !== 0 ) {
|
||||||
details.code = networkFilters.join('\n') + '\n{display:none!important;}';
|
details.code = networkFilters.join('\n') + '\n{display:none!important;}';
|
||||||
|
if ( options.dontInject !== true ) {
|
||||||
vAPI.tabs.insertCSS(request.tabId, details);
|
vAPI.tabs.insertCSS(request.tabId, details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
@ -1125,12 +1129,13 @@ FilterContainer.prototype.benchmark = async function() {
|
|||||||
const options = {
|
const options = {
|
||||||
noCosmeticFiltering: false,
|
noCosmeticFiltering: false,
|
||||||
noGenericCosmeticFiltering: false,
|
noGenericCosmeticFiltering: false,
|
||||||
|
dontInject: true,
|
||||||
};
|
};
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const t0 = self.performance.now();
|
const t0 = self.performance.now();
|
||||||
for ( let i = 0; i < requests.length; i++ ) {
|
for ( let i = 0; i < requests.length; i++ ) {
|
||||||
const request = requests[i];
|
const request = requests[i];
|
||||||
if ( request.cpt !== 'document' ) { continue; }
|
if ( request.cpt !== 'main_frame' ) { continue; }
|
||||||
count += 1;
|
count += 1;
|
||||||
details.hostname = µb.URI.hostnameFromURI(request.url);
|
details.hostname = µb.URI.hostnameFromURI(request.url);
|
||||||
details.domain = µb.URI.domainFromHostname(details.hostname);
|
details.domain = µb.URI.domainFromHostname(details.hostname);
|
||||||
|
@ -97,6 +97,12 @@ const onMessage = function(request, sender, callback) {
|
|||||||
µb.scriptlets.inject(request.tabId, request.scriptlet, callback);
|
µb.scriptlets.inject(request.tabId, request.scriptlet, callback);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case 'sfneBenchmark':
|
||||||
|
µb.staticNetFilteringEngine.benchmark().then(result => {
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -127,7 +133,8 @@ const onMessage = function(request, sender, callback) {
|
|||||||
case 'getAppData':
|
case 'getAppData':
|
||||||
response = {
|
response = {
|
||||||
name: browser.runtime.getManifest().name,
|
name: browser.runtime.getManifest().name,
|
||||||
version: vAPI.app.version
|
version: vAPI.app.version,
|
||||||
|
canBenchmark: µb.hiddenSettings.benchmarkDatasetURL !== 'unset',
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@
|
|||||||
const t0 = self.performance.now();
|
const t0 = self.performance.now();
|
||||||
for ( let i = 0; i < requests.length; i++ ) {
|
for ( let i = 0; i < requests.length; i++ ) {
|
||||||
const request = requests[i];
|
const request = requests[i];
|
||||||
if ( request.cpt !== 'document' ) { continue; }
|
if ( request.cpt !== 'main_frame' ) { continue; }
|
||||||
count += 1;
|
count += 1;
|
||||||
details.url = request.url;
|
details.url = request.url;
|
||||||
details.hostname = µb.URI.hostnameFromURI(request.url);
|
details.hostname = µb.URI.hostnameFromURI(request.url);
|
||||||
|
@ -3544,12 +3544,14 @@ FilterContainer.prototype.benchmark = async function(action, target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const t0 = self.performance.now();
|
const t0 = self.performance.now();
|
||||||
|
let matchCount = 0;
|
||||||
for ( let i = 0; i < requests.length; i++ ) {
|
for ( let i = 0; i < requests.length; i++ ) {
|
||||||
const request = requests[i];
|
const request = requests[i];
|
||||||
fctxt.setURL(request.url);
|
fctxt.setURL(request.url);
|
||||||
fctxt.setDocOriginFromURL(request.frameUrl);
|
fctxt.setDocOriginFromURL(request.frameUrl);
|
||||||
fctxt.setType(request.cpt);
|
fctxt.setType(request.cpt);
|
||||||
const r = this.matchString(fctxt);
|
const r = this.matchString(fctxt);
|
||||||
|
matchCount += 1;
|
||||||
if ( recorded !== undefined ) { recorded.push(r); }
|
if ( recorded !== undefined ) { recorded.push(r); }
|
||||||
if ( expected !== undefined && r !== expected[i] ) {
|
if ( expected !== undefined && r !== expected[i] ) {
|
||||||
print(`Mismatch with reference results at ${i}:`);
|
print(`Mismatch with reference results at ${i}:`);
|
||||||
@ -3558,22 +3560,35 @@ FilterContainer.prototype.benchmark = async function(action, target) {
|
|||||||
print(`\turl=${fctxt.url}`);
|
print(`\turl=${fctxt.url}`);
|
||||||
print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
|
print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
|
||||||
}
|
}
|
||||||
|
if ( fctxt.type === 'main_frame' || fctxt.type === 'sub_frame' ) {
|
||||||
|
this.matchAndFetchData(fctxt, 'csp');
|
||||||
|
matchCount += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const t1 = self.performance.now();
|
const t1 = self.performance.now();
|
||||||
const dur = t1 - t0;
|
const dur = t1 - t0;
|
||||||
|
|
||||||
print(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
|
|
||||||
print(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
|
|
||||||
if ( expected !== undefined ) {
|
|
||||||
print(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
|
|
||||||
print(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
|
|
||||||
}
|
|
||||||
if ( recorded !== undefined ) {
|
if ( recorded !== undefined ) {
|
||||||
vAPI.localStorage.setItem(
|
vAPI.localStorage.setItem(
|
||||||
'FilterContainer.benchmark.results',
|
'FilterContainer.benchmark.results',
|
||||||
JSON.stringify(recorded)
|
JSON.stringify(recorded)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const output = [
|
||||||
|
'Benchmarked static network filtering engine:',
|
||||||
|
`\tEvaluated ${matchCount} match calls in ${dur.toFixed(0)} ms`,
|
||||||
|
`\tAverage: ${(dur / matchCount).toFixed(3)} ms per request`,
|
||||||
|
];
|
||||||
|
if ( expected !== undefined ) {
|
||||||
|
output.push(
|
||||||
|
`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`,
|
||||||
|
`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const s = output.join('\n');
|
||||||
|
print(s);
|
||||||
|
return s;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -819,6 +819,11 @@
|
|||||||
}
|
}
|
||||||
if ( request instanceof Object === false ) { continue; }
|
if ( request instanceof Object === false ) { continue; }
|
||||||
if ( !request.frameUrl || !request.url ) { continue; }
|
if ( !request.frameUrl || !request.url ) { continue; }
|
||||||
|
if ( request.cpt === 'document' ) {
|
||||||
|
request.cpt = 'main_frame';
|
||||||
|
} else if ( request.cpt === 'xhr' ) {
|
||||||
|
request.cpt = 'xmlhttprequest';
|
||||||
|
}
|
||||||
requests.push(request);
|
requests.push(request);
|
||||||
}
|
}
|
||||||
return requests;
|
return requests;
|
||||||
|
Loading…
Reference in New Issue
Block a user