Add more benchmark tools to devtool page

This commit is contained in:
Raymond Hill 2024-03-01 17:26:21 -05:00
parent 9215fefab4
commit 80b66c849a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 80 additions and 27 deletions

View File

@ -29,6 +29,8 @@
<button id="snfe-todnr" type="button">SNFE: DNR<span class="hover"></span></button>
<button id="snfe-benchmark" type="button" disabled>SNFE: Benchmark<span class="hover"></span></button>
<button id="cfe-dump" type="button">CFE: Dump<span class="hover"></span></button>
<button id="cfe-benchmark" type="button">CFE: Benchmark<span class="hover"></span></button>
<button id="sfe-benchmark" type="button">SFE: Benchmark<span class="hover"></span></button>
<button id="purge-all-caches" type="button" data-i18n-title="3pPurgeAll"><span data-i18n="3pPurgeAll">_</span><span class="hover"></span></button>
</div>
<div id="console" class="codeMirrorContainer"></div>

View File

@ -74,8 +74,8 @@ const loadBenchmarkDataset = (( ) => {
datasetPromise = undefined;
});
return function() {
ttlTimer.offon({ min: 5 });
return async function() {
ttlTimer.offon({ min: 2 });
if ( datasetPromise !== undefined ) {
return datasetPromise;
@ -84,7 +84,7 @@ const loadBenchmarkDataset = (( ) => {
const datasetURL = µb.hiddenSettings.benchmarkDatasetURL;
if ( datasetURL === 'unset' ) {
console.info(`No benchmark dataset available.`);
return Promise.resolve();
return;
}
console.info(`Loading benchmark dataset...`);
datasetPromise = io.fetchText(datasetURL).then(details => {
@ -136,7 +136,7 @@ const loadBenchmarkDataset = (( ) => {
// action: 1=test
µb.benchmarkStaticNetFiltering = async function(options = {}) {
export async function benchmarkStaticNetFiltering(options = {}) {
const { target, redirectEngine } = options;
const requests = await loadBenchmarkDataset();
@ -231,11 +231,11 @@ const loadBenchmarkDataset = (( ) => {
const s = output.join('\n');
console.info(s);
return s;
};
}
/******************************************************************************/
µb.tokenHistograms = async function() {
export async function tokenHistogramsfunction() {
const requests = await loadBenchmarkDataset();
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
@ -272,11 +272,11 @@ const loadBenchmarkDataset = (( ) => {
const tophits = Array.from(hitTokenMap).sort(customSort).slice(0, 100);
console.info('Misses:', JSON.stringify(topmisses));
console.info('Hits:', JSON.stringify(tophits));
};
}
/******************************************************************************/
µb.benchmarkDynamicNetFiltering = async function() {
export async function benchmarkDynamicNetFiltering() {
const requests = await loadBenchmarkDataset();
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
@ -299,17 +299,19 @@ const loadBenchmarkDataset = (( ) => {
const dur = t1 - t0;
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
};
}
/******************************************************************************/
µb.benchmarkCosmeticFiltering = async function() {
export async function benchmarkCosmeticFiltering() {
const requests = await loadBenchmarkDataset();
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
return;
}
console.info('Benchmarking cosmeticFilteringEngine.retrieveSpecificSelectors()...');
const output = [
'Benchmarking cosmeticFilteringEngine.retrieveSpecificSelectors()...',
];
const details = {
tabId: undefined,
frameId: undefined,
@ -320,6 +322,7 @@ const loadBenchmarkDataset = (( ) => {
const options = {
noSpecificCosmeticFiltering: false,
noGenericCosmeticFiltering: false,
dontInject: true,
};
let count = 0;
const t0 = performance.now();
@ -334,19 +337,26 @@ const loadBenchmarkDataset = (( ) => {
}
const t1 = performance.now();
const dur = t1 - t0;
console.info(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
console.info(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
};
output.push(
`Evaluated ${count} retrieval in ${dur.toFixed(0)} ms`,
`\tAverage: ${(dur / count).toFixed(3)} ms per document`
);
const s = output.join('\n');
console.info(s);
return s;
}
/******************************************************************************/
µb.benchmarkScriptletFiltering = async function() {
export async function benchmarkScriptletFiltering() {
const requests = await loadBenchmarkDataset();
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
return;
}
console.info('Benchmarking scriptletFilteringEngine.retrieve()...');
const output = [
'Benchmarking scriptletFilteringEngine.retrieve()...',
];
const details = {
domain: '',
entity: '',
@ -369,13 +379,18 @@ const loadBenchmarkDataset = (( ) => {
}
const t1 = performance.now();
const dur = t1 - t0;
console.info(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
console.info(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
};
output.push(
`Evaluated ${count} retrieval in ${dur.toFixed(0)} ms`,
`\tAverage: ${(dur / count).toFixed(3)} ms per document`
);
const s = output.join('\n');
console.info(s);
return s;
}
/******************************************************************************/
µb.benchmarkOnBeforeRequest = async function() {
export async function benchmarkOnBeforeRequest() {
const requests = await loadBenchmarkDataset();
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
@ -417,6 +432,6 @@ const loadBenchmarkDataset = (( ) => {
console.info(`\tBlocked ${blockCount} requests`);
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
});
};
}
/******************************************************************************/

View File

@ -930,7 +930,7 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
if ( injectedCSS.length !== 0 ) {
out.injectedCSS = injectedCSS.join('\n\n');
details.code = out.injectedCSS;
if ( request.tabId !== undefined ) {
if ( request.tabId !== undefined && options.dontInject !== true ) {
vAPI.tabs.insertCSS(request.tabId, details);
}
}
@ -940,7 +940,7 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
const networkFilters = [];
if ( cacheEntry.retrieveNet(networkFilters) ) {
details.code = `${networkFilters.join('\n')}\n{display:none!important;}`;
if ( request.tabId !== undefined ) {
if ( request.tabId !== undefined && options.dontInject !== true ) {
vAPI.tabs.insertCSS(request.tabId, details);
}
}

View File

@ -187,6 +187,26 @@ vAPI.messaging.send('dashboard', {
dom.attr(button, 'disabled', null);
});
});
dom.on('#cfe-benchmark', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('devTools', {
what: 'cfeBenchmark',
}).then(result => {
log(result);
dom.attr(button, 'disabled', null);
});
});
dom.on('#sfe-benchmark', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('devTools', {
what: 'sfeBenchmark',
}).then(result => {
log(result);
dom.attr(button, 'disabled', null);
});
});
});
/******************************************************************************/

View File

@ -64,8 +64,6 @@ import {
isNetworkURI,
} from './uri-utils.js';
import './benchmarks.js';
/******************************************************************************/
// https://github.com/uBlockOrigin/uBlock-issues/issues/710
@ -1847,8 +1845,26 @@ const onMessage = function(request, sender, callback) {
return;
case 'snfeBenchmark':
µb.benchmarkStaticNetFiltering({ redirectEngine }).then(result => {
callback(result);
import('/js/benchmarks.js').then(module => {
module.benchmarkStaticNetFiltering({ redirectEngine }).then(result => {
callback(result);
});
});
return;
case 'cfeBenchmark':
import('/js/benchmarks.js').then(module => {
module.benchmarkCosmeticFiltering().then(result => {
callback(result);
});
});
return;
case 'sfeBenchmark':
import('/js/benchmarks.js').then(module => {
module.benchmarkScriptletFiltering().then(result => {
callback(result);
});
});
return;