Skip to content

Commit 5733439

Browse files
committed
Leverage whotracks.me's huge dataset of URLs for benchmark purpose
As seen at: https://whotracks.me/blog/adblockers_performance_study.html The requests.json.gz file can be downloaded from: https://cdn.cliqz.com/adblocking/requests_top500.json.gz Copy the file into ./tmp/requests.json.gz If the file is present when you build uBO using `make-[target].sh` from the shell, the resulting package will contain `./assets/requests.json`, which will be looked-up by the method below to launch a benchmark session. From uBO's dev console, launch the benchmark: µBlock.staticNetFilteringEngine.benchmark(); The usual browser dev tools can be used to obtain useful profiling data, i.e. start the profiler, call the benchmark method from the console, then stop the profiler when it completes. Keep in mind that the measurements at the blog post above where obtained with ONLY EasyList. The CPU reportedly used was: https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-6600U+%40+2.60GHz&id=2608 Rename ./tmp/requests.json.gz to something else if you no longer want ./assets/requests.json in the build.
1 parent e589e28 commit 5733439

File tree

2 files changed

+72
-9
lines changed

2 files changed

+72
-9
lines changed

src/js/static-net-filtering.js

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const typeNameToTypeValue = {
5858
'object': 3 << 4,
5959
'object_subrequest': 3 << 4,
6060
'script': 4 << 4,
61+
'fetch': 5 << 4,
6162
'xmlhttprequest': 5 << 4,
6263
'sub_frame': 6 << 4,
6364
'font': 7 << 4,
@@ -2792,14 +2793,72 @@ FilterContainer.prototype.getFilterCount = function() {
27922793

27932794
/******************************************************************************/
27942795

2795-
FilterContainer.prototype.benchmark = function(contexts) {
2796-
const t0 = performance.now();
2797-
const results = [];
2798-
for ( const context of contexts ) {
2799-
results.push(this.matchString(context));
2800-
}
2801-
const t1 = performance.now();
2802-
return { t0, t1, duration: t1 - t0, results };
2796+
// The requests.json.gz file can be downloaded from:
2797+
// https://cdn.cliqz.com/adblocking/requests_top500.json.gz
2798+
//
2799+
// Which is linked from:
2800+
// https://whotracks.me/blog/adblockers_performance_study.html
2801+
//
2802+
// Copy the file into ./tmp/requests.json.gz
2803+
//
2804+
// If the file is present when you build uBO using `make-[target].sh` from
2805+
// the shell, the resulting package will have `./assets/requests.json`, which
2806+
// will be looked-up by the method below to launch a benchmark session.
2807+
//
2808+
// From uBO's dev console, launch the benchmark:
2809+
// µBlock.staticNetFilteringEngine.benchmark();
2810+
//
2811+
// The usual browser dev tools can be used to obtain useful profiling
2812+
// data, i.e. start the profiler, call the benchmark method from the
2813+
// console, then stop the profiler when it completes.
2814+
//
2815+
// Keep in mind that the measurements at the blog post above where obtained
2816+
// with ONLY EasyList. The CPU reportedly used was:
2817+
// https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-6600U+%40+2.60GHz&id=2608
2818+
//
2819+
// Rename ./tmp/requests.json.gz to something else if you no longer want
2820+
// ./assets/requests.json in the build.
2821+
2822+
FilterContainer.prototype.benchmark = function() {
2823+
new Promise(resolve => {
2824+
const url = vAPI.getURL('/assets/requests.json');
2825+
µb.assets.fetchText(vAPI.getURL('/assets/requests.json'), details => {
2826+
if ( details.error !== undefined ) {
2827+
console.info(`Not found: ${url}`);
2828+
resolve();
2829+
return;
2830+
}
2831+
const requests = [];
2832+
const lineIter = new µb.LineIterator(details.content);
2833+
while ( lineIter.eot() === false ) {
2834+
let request;
2835+
try {
2836+
request = JSON.parse(lineIter.next());
2837+
} catch(ex) {
2838+
}
2839+
if ( request instanceof Object === false ) { continue; }
2840+
requests.push(request);
2841+
}
2842+
resolve(requests);
2843+
});
2844+
}).then(requests => {
2845+
if ( Array.isArray(requests) === false || requests.length === 0 ) {
2846+
console.info('No requests found to benchmark');
2847+
return;
2848+
}
2849+
const fctxt = µb.filteringContext;
2850+
const t0 = self.performance.now();
2851+
for ( const request of requests ) {
2852+
fctxt.url = request.url;
2853+
fctxt.setDocOriginFromURL(request.frameUrl);
2854+
fctxt.setType(request.cpt);
2855+
void this.matchString(fctxt);
2856+
}
2857+
const t1 = self.performance.now();
2858+
const dur = t1 - t0;
2859+
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
2860+
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
2861+
});
28032862
};
28042863

28052864
/******************************************************************************/

tools/make-assets.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ fi
1414

1515
rm -rf $DES
1616
mkdir $DES
17-
cp ./assets/assets.json $DES/
17+
cp ./assets/assets.json $DES/
18+
19+
if [ -f ./tmp/requests.json.gz ]; then
20+
gunzip -c ./tmp/requests.json.gz > $DES/requests.json
21+
fi
1822

1923
mkdir $DES/thirdparties
2024
cp -R ../uAssets/thirdparties/easylist-downloads.adblockplus.org $DES/thirdparties/

0 commit comments

Comments
 (0)