From a594b3f3d19a40c1d4244c013101c456a801e10f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 15 Apr 2019 11:45:33 -0400 Subject: [PATCH] =?UTF-8?q?Add=20=C2=B5Block.staticNetFilteringEngine.buck?= =?UTF-8?q?etHistogram()=20as=20investigative=20dev=20tool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additionally, lower the treshold of trieability to 4 for FilterPlainPrefix1. --- src/js/static-net-filtering.js | 19 ++++++++++++++++++- src/js/utils.js | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 4fbc94f78..91cec9ff9 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -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(); /******************************************************************************/ diff --git a/src/js/utils.js b/src/js/utils.js index 88e51e361..b50de5fd1 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -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.