Add µBlock.staticNetFilteringEngine.bucketHistogram() as investigative dev tool

Additionally, lower the treshold of trieability to 4 for FilterPlainPrefix1.
This commit is contained in:
Raymond Hill 2019-04-15 11:45:33 -04:00
parent 5b202b9d5c
commit a594b3f3d1
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 31 additions and 1 deletions

View File

@ -1286,7 +1286,7 @@ const FilterBucket = class {
FilterPlainPrefix1.trieableStringFromArgs(fdata)
);
}
if ( this.plainPrefix1Count === 7 ) {
if ( this.plainPrefix1Count === 3 ) {
this.plainPrefix1Trie = FilterBucket.trieContainer.createOne();
this._transferTrieable(
this.plainPrefix1Id,
@ -2867,6 +2867,23 @@ FilterContainer.prototype.benchmark = function(action) {
/******************************************************************************/
FilterContainer.prototype.bucketHistogram = function() {
const results = [];
for ( const [ bits, category ] of this.categories ) {
for ( const [ th, f ] of category ) {
if ( f instanceof FilterBucket === false ) { continue; }
const token = µBlock.urlTokenizer.stringFromTokenHash(th);
results.push({ bits, token, size: f.size, f });
}
}
results.sort((a, b) => {
return b.size - a.size;
});
console.log(results);
};
/******************************************************************************/
return new FilterContainer();
/******************************************************************************/

View File

@ -75,6 +75,19 @@
return th;
},
stringFromTokenHash: function(th) {
if ( th === 0 ) { return ''; }
if ( th === 63 ) { return '*'; }
if ( th === 62 ) { return '.'; }
const chars = '0123456789%abcdefghijklmnopqrstuvwxyz';
let s = '';
while ( th > 0 ) {
s = `${chars.charAt((th & 0b111111)-1)}${s}`;
th /= 64;
}
return s;
},
// https://github.com/chrisaljoudi/uBlock/issues/1118
// We limit to a maximum number of tokens.