Increase URL buffer size to 8192 (from 2048)

Related:
https://github.com/easylist/easylist/commit/777d7ba9
This commit is contained in:
Raymond Hill 2025-03-01 14:48:51 -05:00
parent cff88d547f
commit 36404543e4
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
9 changed files with 74 additions and 86 deletions

View file

@ -33,7 +33,7 @@
<button id="sfe-benchmark" type="button" disabled>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>
<div id="console" class="codeMirrorContainer codeMirrorBreakAll"></div>
<script src="lib/codemirror/lib/codemirror.js"></script>
<script src="lib/codemirror/addon/display/panel.js"></script>

View file

@ -181,7 +181,7 @@ const µBlock = { // jshint ignore:line
// Read-only
systemSettings: {
compiledMagic: 57, // Increase when compiled format changes
selfieMagic: 58, // Increase when selfie format changes
selfieMagic: 59, // Increase when selfie format changes
},
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501

View file

@ -24,13 +24,16 @@
A BidiTrieContainer is mostly a large buffer in which distinct but related
tries are stored. The memory layout of the buffer is as follow:
0-2047: haystack section
2048-2051: number of significant characters in the haystack
2052-2055: offset to start of trie data section (=> trie0)
2056-2059: offset to end of trie data section (=> trie1)
2060-2063: offset to start of character data section (=> char0)
2064-2067: offset to end of character data section (=> char1)
2068: start of trie data section
0-8192: haystack section
8192-8195: number of significant characters in the haystack
8196-8199: offset to start of trie data section (=> trie0)
8200-8203: offset to end of trie data section (=> trie1)
8204-8207: offset to start of character data section (=> char0)
8208-8211: offset to end of character data section (=> char1)
8212-8215: offset to left index result (=> result_l)
8216-8219: offset to right index result (=> result_r)
8220-8223: offset to extra unit result (=> result_iu)
8224: start of trie data section
+--------------+
Normal cell: | And | If "Segment info" matches:
@ -93,18 +96,19 @@
*/
const VERSION = 2;
const PAGE_SIZE = 65536*2;
const HAYSTACK_START = 0;
const HAYSTACK_SIZE = 2048; // i32 / i8
const HAYSTACK_SIZE_SLOT = HAYSTACK_SIZE >>> 2; // 512 / 2048
const TRIE0_SLOT = HAYSTACK_SIZE_SLOT + 1; // 513 / 2052
const TRIE1_SLOT = HAYSTACK_SIZE_SLOT + 2; // 514 / 2056
const CHAR0_SLOT = HAYSTACK_SIZE_SLOT + 3; // 515 / 2060
const CHAR1_SLOT = HAYSTACK_SIZE_SLOT + 4; // 516 / 2064
const RESULT_L_SLOT = HAYSTACK_SIZE_SLOT + 5; // 517 / 2068
const RESULT_R_SLOT = HAYSTACK_SIZE_SLOT + 6; // 518 / 2072
const RESULT_IU_SLOT = HAYSTACK_SIZE_SLOT + 7; // 519 / 2076
const TRIE0_START = HAYSTACK_SIZE_SLOT + 8 << 2; // 2080
const HAYSTACK_SIZE = 8192; // i32 / i8
const HAYSTACK_SIZE_SLOT = HAYSTACK_SIZE >>> 2; // 2048 / 8192
const TRIE0_SLOT = HAYSTACK_SIZE_SLOT + 1; // 2049 / 8196
const TRIE1_SLOT = HAYSTACK_SIZE_SLOT + 2; // 2050 / 8200
const CHAR0_SLOT = HAYSTACK_SIZE_SLOT + 3; // 2051 / 8204
const CHAR1_SLOT = HAYSTACK_SIZE_SLOT + 4; // 2052 / 8208
const RESULT_L_SLOT = HAYSTACK_SIZE_SLOT + 5; // 2053 / 8212
const RESULT_R_SLOT = HAYSTACK_SIZE_SLOT + 6; // 2054 / 8216
const RESULT_IU_SLOT = HAYSTACK_SIZE_SLOT + 7; // 2055 / 8220
const TRIE0_START = HAYSTACK_SIZE_SLOT + 8 << 2; // 8224
const CELL_BYTE_LENGTH = 12;
const MIN_FREE_CELL_BYTE_LENGTH = CELL_BYTE_LENGTH * 8;
@ -156,28 +160,21 @@ class BidiTrieContainer {
// Public methods
//--------------------------------------------------------------------------
get haystackLen() {
getHaystackLen() {
return this.buf32[HAYSTACK_SIZE_SLOT];
}
set haystackLen(v) {
setHaystackLen(v) {
if ( v > HAYSTACK_SIZE ) {
v = HAYSTACK_SIZE;
}
this.buf32[HAYSTACK_SIZE_SLOT] = v;
return v;
}
reset(details) {
if (
details instanceof Object &&
typeof details.byteLength === 'number' &&
typeof details.char0 === 'number'
) {
if ( details.byteLength > this.buf8.byteLength ) {
this.reallocateBuf(details.byteLength);
}
this.buf32[CHAR0_SLOT] = details.char0;
}
reset() {
this.buf32[TRIE1_SLOT] = this.buf32[TRIE0_SLOT];
this.buf32[CHAR1_SLOT] = this.buf32[CHAR0_SLOT];
this.lastStored = '';
this.lastStoredLen = this.lastStoredIndex = 0;
}
@ -571,23 +568,22 @@ class BidiTrieContainer {
this.buf32[iboundary+BCELL_EXTRA] = v;
}
optimize(shrink = false) {
if ( shrink ) {
this.shrinkBuf();
}
return {
byteLength: this.buf8.byteLength,
char0: this.buf32[CHAR0_SLOT],
};
optimize() {
this.shrinkBuf();
}
toSelfie() {
const buf32 = this.buf32.subarray(0, this.buf32[CHAR1_SLOT] + 3 >>> 2);
return { buf32, checksum: i32Checksum(buf32) };
return {
version: VERSION,
buf32,
checksum: i32Checksum(buf32),
};
}
fromSelfie(selfie) {
if ( typeof selfie !== 'object' || selfie === null ) { return false; }
if ( selfie.version !== VERSION ) { return false; }
if ( selfie.buf32 instanceof Uint32Array === false ) { return false; }
if ( selfie.checksum !== i32Checksum(selfie.buf32) ) { return false; }
const byteLength = selfie.buf32.length << 2;

View file

@ -331,6 +331,7 @@ cmEditor.on('beforeChange', (cm, details) => {
const fields = line.slice(5).split(/\s+/);
const query = {};
for ( const field of fields ) {
if ( field === '' ) { continue; }
if ( /[/.]/.test(field) ) {
if ( query.url === undefined ) {
query.url = field;

View file

@ -1422,8 +1422,14 @@ if ( isInstanceOf(globalThis, 'DedicatedWorkerGlobalScope') ) {
break;
}
case THREAD_DESERIALIZE: {
const result = deserialize(msg.data);
globalThis.postMessage({ id: msg.id, size: msg.size, result });
let result;
try {
result = deserialize(msg.data);
} catch(ex) {
console.error(ex);
} finally {
globalThis.postMessage({ id: msg.id, size: msg.size, result });
}
break;
}
default:

View file

@ -550,14 +550,6 @@ const bidiTrieMatchExtra = (l, r, ix) => {
const bidiTrie = new BidiTrieContainer(bidiTrieMatchExtra);
const bidiTriePrime = ( ) => {
bidiTrie.reset(keyvalStore.getItem('SNFE.bidiTrie'));
};
const bidiTrieOptimize = (shrink = false) => {
keyvalStore.setItem('SNFE.bidiTrie', bidiTrie.optimize(shrink));
};
/*******************************************************************************
Each filter class will register itself in the map.
@ -800,7 +792,7 @@ class FilterPatternPlain {
if (
bidiTrie.startsWith(
left,
bidiTrie.haystackLen,
bidiTrie.getHaystackLen(),
filterData[idata+1],
n
) === 0
@ -877,7 +869,7 @@ class FilterPatternPlain1 extends FilterPatternPlain {
if (
bidiTrie.startsWith(
left,
bidiTrie.haystackLen,
bidiTrie.getHaystackLen(),
filterData[idata+1],
n
) === 0
@ -900,7 +892,7 @@ class FilterPatternPlainX extends FilterPatternPlain {
if (
bidiTrie.startsWith(
left,
bidiTrie.haystackLen,
bidiTrie.getHaystackLen(),
filterData[idata+1],
n
) === 0
@ -1035,7 +1027,7 @@ class FilterAnchorHnLeft {
lastBeg = len !== 0 ? haystackCodes.indexOf(0x3A) : -1;
if ( lastBeg !== -1 ) {
if (
lastBeg >= bidiTrie.haystackLen ||
lastBeg >= bidiTrie.getHaystackLen() ||
haystackCodes[lastBeg+1] !== 0x2F ||
haystackCodes[lastBeg+2] !== 0x2F
) {
@ -3199,14 +3191,9 @@ const urlTokenizer = new (class {
_tokenize(encodeInto) {
const tokens = this._tokens;
let url = this._urlOut;
let l = url.length;
const url = this._urlOut;
const l = encodeInto.setHaystackLen(url.length);
if ( l === 0 ) { return 0; }
if ( l > 2048 ) {
url = url.slice(0, 2048);
l = 2048;
}
encodeInto.haystackLen = l;
let j = 0;
let hasq = -1;
mainLoop: {
@ -4197,7 +4184,6 @@ StaticNetFilteringEngine.prototype.prime = function() {
destHNTrieContainer.reset(
keyvalStore.getItem('SNFE.destHNTrieContainer.trieDetails')
);
bidiTriePrime();
};
/******************************************************************************/
@ -4793,7 +4779,6 @@ StaticNetFilteringEngine.prototype.optimize = function(throttle = 0) {
'SNFE.destHNTrieContainer.trieDetails',
destHNTrieContainer.optimize()
);
bidiTrieOptimize();
filterDataShrink();
};
@ -4801,7 +4786,7 @@ StaticNetFilteringEngine.prototype.optimize = function(throttle = 0) {
StaticNetFilteringEngine.prototype.toSelfie = function() {
this.optimize(0);
bidiTrieOptimize(true);
bidiTrie.optimize();
keyvalStore.setItem('SNFE.origHNTrieContainer.trieDetails',
origHNTrieContainer.optimize()
);

View file

@ -13,7 +13,7 @@ Assuming:
### `wat2wasm` tool
The `wat2wasm` tool can be downloaded from an official WebAssembly project:
<https://github.com/WebAssembly/wabt/releases>.
<https://github.com/WebAssembly/wabt/releases/tag/1.0.29>
### `wat2wasm` tool online

Binary file not shown.

View file

@ -32,16 +32,16 @@
;;
;; Memory layout, byte offset:
;; const HAYSTACK_START = 0;
;; const HAYSTACK_SIZE = 2048; // i32 / i8
;; const HAYSTACK_SIZE_SLOT = HAYSTACK_SIZE >>> 2; // 512 / 2048
;; const TRIE0_SLOT = HAYSTACK_SIZE_SLOT + 1; // 513 / 2052
;; const TRIE1_SLOT = HAYSTACK_SIZE_SLOT + 2; // 514 / 2056
;; const CHAR0_SLOT = HAYSTACK_SIZE_SLOT + 3; // 515 / 2060
;; const CHAR1_SLOT = HAYSTACK_SIZE_SLOT + 4; // 516 / 2064
;; const RESULT_L_SLOT = HAYSTACK_SIZE_SLOT + 5; // 517 / 2068
;; const RESULT_R_SLOT = HAYSTACK_SIZE_SLOT + 6; // 518 / 2072
;; const RESULT_IU_SLOT = HAYSTACK_SIZE_SLOT + 7; // 519 / 2076
;; const TRIE0_START = HAYSTACK_SIZE_SLOT + 8 << 2; // 2080
;; const HAYSTACK_SIZE = 8192; // i32 / i8
;; const HAYSTACK_SIZE_SLOT = HAYSTACK_SIZE >>> 2; // 2048 / 8192
;; const TRIE0_SLOT = HAYSTACK_SIZE_SLOT + 1; // 2049 / 8196
;; const TRIE1_SLOT = HAYSTACK_SIZE_SLOT + 2; // 2050 / 8200
;; const CHAR0_SLOT = HAYSTACK_SIZE_SLOT + 3; // 2051 / 8204
;; const CHAR1_SLOT = HAYSTACK_SIZE_SLOT + 4; // 2052 / 8208
;; const RESULT_L_SLOT = HAYSTACK_SIZE_SLOT + 5; // 2053 / 8212
;; const RESULT_R_SLOT = HAYSTACK_SIZE_SLOT + 6; // 2054 / 8216
;; const RESULT_IU_SLOT = HAYSTACK_SIZE_SLOT + 7; // 2055 / 8220
;; const TRIE0_START = HAYSTACK_SIZE_SLOT + 8 << 2; // 8224
;;
;;
@ -71,11 +71,11 @@
;; const buf32 = this.buf32;
;; const buf8 = this.buf8;
;; const char0 = buf32[CHAR0_SLOT];
i32.const 2060
i32.const 8204
i32.load align=4
local.set $char0
;; const aR = buf32[HAYSTACK_SIZE_SLOT];
i32.const 2048
i32.const 8192
i32.load align=4
local.set $aR
;; let al = ai;
@ -253,7 +253,7 @@
;; const buf32 = this.buf32;
;; const buf8 = this.buf8;
;; const char0 = buf32[CHAR0_SLOT];
i32.const 2060
i32.const 8204
i32.load align=4
local.set $char0
block $matchFound
@ -433,15 +433,15 @@
;; }
end
;; this.buf32[RESULT_IU_SLOT] = iu;
i32.const 2076
i32.const 8220
local.get $iu
i32.store align=4
;; this.buf32[RESULT_L_SLOT] = l;
i32.const 2068
i32.const 8212
local.get $l
i32.store align=4
;; this.buf32[RESULT_R_SLOT] = r;
i32.const 2072
i32.const 8216
local.get $r
i32.store align=4
end ;; $succeed
@ -483,7 +483,7 @@
;; const charCodes = this.buf8;
;; needleLeft += this.buf32[CHAR0_SLOT];
local.get $needleLeft
i32.const 2060 ;; CHAR0_SLOT memory address
i32.const 8204 ;; CHAR0_SLOT memory address
i32.load align=4 ;; CHAR0 memory address
i32.add ;; needle memory address
local.tee $needleLeft
@ -559,7 +559,7 @@
br_if $fail
;; needleLeft += this.buf32[CHAR0_SLOT];
local.get $needleLeft
i32.const 2060 ;; CHAR0_SLOT memory address
i32.const 8204 ;; CHAR0_SLOT memory address
i32.load align=4 ;; CHAR0 memory address
i32.add ;; needle memory address
local.tee $needleLeft
@ -659,7 +659,7 @@
br_if $fail
;; needleLeft += this.buf32[CHAR0_SLOT];
local.get $needleLeft
i32.const 2060 ;; CHAR0_SLOT memory address
i32.const 8204 ;; CHAR0_SLOT memory address
i32.load align=4 ;; CHAR0 memory address
i32.add ;; needle memory address
local.tee $needleLeft