@gmitch215/folio 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -460
- package/dist/boot.d.ts +1 -0
- package/dist/boot.js +1 -0
- package/dist/browser/index.d.ts +73 -0
- package/dist/browser/index.js +277 -0
- package/dist/browser.d.ts +1 -68
- package/dist/browser.js +1 -274
- package/dist/continuation.d.ts +1 -0
- package/dist/continuation.js +1 -0
- package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
- package/dist/{compiler.js → execution/compiler.js} +5 -12
- package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
- package/dist/{coordinator.js → execution/coordinator.js} +55 -8
- package/dist/{extract.d.ts → execution/extract.d.ts} +22 -13
- package/dist/{extract.js → execution/extract.js} +137 -10
- package/dist/execution/fold.d.ts +44 -0
- package/dist/execution/fold.js +105 -0
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/runs.d.ts +44 -0
- package/dist/execution/runs.js +182 -0
- package/dist/{transaction.d.ts → execution/transaction.d.ts} +10 -0
- package/dist/execution/types.d.ts +221 -0
- package/dist/folds/affine-state.d.ts +142 -0
- package/dist/folds/affine-state.js +737 -0
- package/dist/folds/affine.d.ts +148 -0
- package/dist/folds/affine.js +562 -0
- package/dist/folds/boundaries.d.ts +48 -0
- package/dist/folds/boundaries.js +119 -0
- package/dist/folds/certified.d.ts +55 -0
- package/dist/folds/certified.js +178 -0
- package/dist/folds/certify.d.ts +87 -0
- package/dist/folds/certify.js +2611 -0
- package/dist/footprints/memo.d.ts +74 -0
- package/dist/footprints/memo.js +256 -0
- package/dist/footprints/ranges.d.ts +78 -0
- package/dist/footprints/ranges.js +263 -0
- package/dist/footprints/read-scan.d.ts +18 -0
- package/dist/footprints/read-scan.js +94 -0
- package/dist/footprints/read-windows.d.ts +77 -0
- package/dist/footprints/read-windows.js +245 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/iteration/admission.d.ts +149 -0
- package/dist/iteration/admission.js +201 -0
- package/dist/iteration/index.d.ts +239 -0
- package/dist/iteration/index.js +1210 -0
- package/dist/iteration/inline.d.ts +182 -0
- package/dist/{inline.js → iteration/inline.js} +277 -21
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +16 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +6 -5
- package/dist/iteration/worker.js +216 -0
- package/dist/{managed.d.ts → managed/index.d.ts} +75 -3
- package/dist/managed/index.js +817 -0
- package/dist/managed/outbox.d.ts +128 -0
- package/dist/managed/outbox.js +156 -0
- package/dist/managed/pool.d.ts +221 -0
- package/dist/managed/pool.js +310 -0
- package/dist/managed/tasks.d.ts +154 -0
- package/dist/managed/tasks.js +183 -0
- package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
- package/dist/{bake.js → memory/bake.js} +9 -7
- package/dist/memory/continuation.d.ts +141 -0
- package/dist/memory/continuation.js +495 -0
- package/dist/memory/elastic-peer.d.ts +20 -0
- package/dist/memory/elastic-peer.js +39 -0
- package/dist/memory/elastic-sql.d.ts +11 -0
- package/dist/memory/elastic-sql.js +35 -0
- package/dist/memory/elastic.d.ts +130 -0
- package/dist/memory/elastic.js +475 -0
- package/dist/memory/growth-governor.d.ts +16 -0
- package/dist/memory/growth-governor.js +42 -0
- package/dist/memory/imports.d.ts +10 -0
- package/dist/memory/imports.js +89 -0
- package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +61 -1
- package/dist/{iteration-layout.js → memory/iteration-layout.js} +54 -3
- package/dist/memory/lease.d.ts +45 -0
- package/dist/memory/lease.js +274 -0
- package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
- package/dist/memory.d.ts +5 -10
- package/dist/memory.js +5 -89
- package/dist/{context.d.ts → node/context.d.ts} +17 -3
- package/dist/{context.js → node/context.js} +60 -14
- package/dist/{host.d.ts → node/host.d.ts} +1 -1
- package/dist/{host.js → node/host.js} +2 -2
- package/dist/{node.d.ts → node/index.d.ts} +46 -49
- package/dist/{node.js → node/index.js} +101 -26
- package/dist/{tasks.d.ts → node/tasks.d.ts} +16 -17
- package/dist/{tasks.js → node/tasks.js} +12 -11
- package/dist/node/worker.d.ts +1 -0
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/ownership/index.d.ts +161 -0
- package/dist/ownership/index.js +6565 -0
- package/dist/ownership/redirect.d.ts +30 -0
- package/dist/ownership/redirect.js +179 -0
- package/dist/ownership/slices.d.ts +44 -0
- package/dist/ownership/slices.js +72 -0
- package/dist/{frames.d.ts → remote/frames.d.ts} +6 -2
- package/dist/remote/frames.js +306 -0
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/routing/index.d.ts +203 -0
- package/dist/routing/index.js +671 -0
- package/dist/routing/worker.d.ts +1 -0
- package/dist/routing/worker.js +4 -0
- package/dist/slices/index.d.ts +126 -0
- package/dist/slices/index.js +441 -0
- package/dist/slices/worker.d.ts +1 -0
- package/dist/slices/worker.js +38 -0
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +32 -46
- package/dist/frames.js +0 -159
- package/dist/inline.d.ts +0 -68
- package/dist/iteration-admission.d.ts +0 -76
- package/dist/iteration-admission.js +0 -72
- package/dist/iteration-worker.js +0 -150
- package/dist/iteration.d.ts +0 -163
- package/dist/iteration.js +0 -435
- package/dist/managed.js +0 -421
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.js} +0 -0
- /package/dist/{guards.js → execution/guards.js} +0 -0
- /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
- /package/dist/{import-order.js → execution/import-order.js} +0 -0
- /package/dist/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmitch215/folio",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "WebAssembly tooling for Node, Workers and browsers: shared-memory parallelism, instance resets, boot images and memory caps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webassembly",
|
|
7
7
|
"wasm",
|
|
8
|
+
"tooling",
|
|
8
9
|
"parallel",
|
|
9
10
|
"worker_threads",
|
|
10
11
|
"sharedarraybuffer",
|
|
12
|
+
"checkpoint",
|
|
13
|
+
"snapshot",
|
|
14
|
+
"memory",
|
|
11
15
|
"cloudflare-workers",
|
|
12
|
-
"workerd"
|
|
16
|
+
"workerd",
|
|
17
|
+
"browser"
|
|
13
18
|
],
|
|
14
19
|
"license": "MIT",
|
|
15
20
|
"author": "Gregory Mitchell <me@gmitch215.xyz>",
|
|
@@ -22,45 +27,25 @@
|
|
|
22
27
|
"types": "./dist/index.d.ts",
|
|
23
28
|
"import": "./dist/index.js"
|
|
24
29
|
},
|
|
25
|
-
"./
|
|
26
|
-
"types": "./dist/
|
|
27
|
-
"import": "./dist/
|
|
28
|
-
},
|
|
29
|
-
"./compiler": {
|
|
30
|
-
"types": "./dist/compiler.d.ts",
|
|
31
|
-
"import": "./dist/compiler.js"
|
|
32
|
-
},
|
|
33
|
-
"./remote": {
|
|
34
|
-
"types": "./dist/remote.d.ts",
|
|
35
|
-
"import": "./dist/remote.js"
|
|
36
|
-
},
|
|
37
|
-
"./host": {
|
|
38
|
-
"types": "./dist/host.d.ts",
|
|
39
|
-
"import": "./dist/host.js"
|
|
40
|
-
},
|
|
41
|
-
"./managed": {
|
|
42
|
-
"types": "./dist/managed.d.ts",
|
|
43
|
-
"import": "./dist/managed.js"
|
|
30
|
+
"./workers": {
|
|
31
|
+
"types": "./dist/workers.d.ts",
|
|
32
|
+
"import": "./dist/workers.js"
|
|
44
33
|
},
|
|
45
34
|
"./browser": {
|
|
46
35
|
"types": "./dist/browser.d.ts",
|
|
47
36
|
"import": "./dist/browser.js"
|
|
48
37
|
},
|
|
49
|
-
"./
|
|
50
|
-
"types": "./dist/
|
|
51
|
-
"import": "./dist/
|
|
52
|
-
},
|
|
53
|
-
"./bake": {
|
|
54
|
-
"types": "./dist/bake.d.ts",
|
|
55
|
-
"import": "./dist/bake.js"
|
|
38
|
+
"./memory": {
|
|
39
|
+
"types": "./dist/memory.d.ts",
|
|
40
|
+
"import": "./dist/memory.js"
|
|
56
41
|
},
|
|
57
|
-
"./
|
|
58
|
-
"types": "./dist/
|
|
59
|
-
"import": "./dist/
|
|
42
|
+
"./boot": {
|
|
43
|
+
"types": "./dist/boot.d.ts",
|
|
44
|
+
"import": "./dist/boot.js"
|
|
60
45
|
},
|
|
61
|
-
"./
|
|
62
|
-
"types": "./dist/
|
|
63
|
-
"import": "./dist/
|
|
46
|
+
"./continuation": {
|
|
47
|
+
"types": "./dist/continuation.d.ts",
|
|
48
|
+
"import": "./dist/continuation.js"
|
|
64
49
|
},
|
|
65
50
|
"./package.json": "./package.json"
|
|
66
51
|
},
|
|
@@ -76,8 +61,8 @@
|
|
|
76
61
|
"build": "tsc -p tsconfig.build.json",
|
|
77
62
|
"build:c": "bun scripts/build/fixtures.ts",
|
|
78
63
|
"build:prepared": "bun scripts/build/prepare.ts",
|
|
79
|
-
"build:experiments": "node experiments/managed/prepare.ts && node experiments/browser/prepare.ts && node experiments/browser/extraction/prepare.ts && node experiments/consumer/prepare.ts kernel-control",
|
|
80
|
-
"typecheck": "bun run build:c && bun run build:experiments && tsc --noEmit -p tsconfig.json && tsc --noEmit -p experiments/cloud/tsconfig.json && tsc --noEmit -p experiments/managed/tsconfig.json && tsc --noEmit -p experiments/browser/tsconfig.json && tsc --noEmit -p experiments/consumer/tsconfig.json && tsc --noEmit -p experiments/rpc/tsconfig.json",
|
|
64
|
+
"build:experiments": "node experiments/managed/prepare.ts && node experiments/browser/prepare.ts && node experiments/browser/extraction/prepare.ts && node experiments/consumer/prepare.ts kernel-control && node experiments/ranges/prepare.ts && node experiments/elastic-ladder/prepare.ts",
|
|
65
|
+
"typecheck": "bun run build:c && bun run build:experiments && tsc --noEmit -p tsconfig.json && tsc --noEmit -p experiments/cloud/tsconfig.json && tsc --noEmit -p experiments/managed/tsconfig.json && tsc --noEmit -p experiments/elastic/tsconfig.json && tsc --noEmit -p experiments/elastic-limits/tsconfig.json && tsc --noEmit -p experiments/elastic-ladder/tsconfig.json && tsc --noEmit -p experiments/browser/tsconfig.json && tsc --noEmit -p experiments/consumer/tsconfig.json && tsc --noEmit -p experiments/rpc/tsconfig.json && tsc --noEmit -p experiments/ranges/tsconfig.json && tsc --noEmit -p experiments/concurrency/tsconfig.json && tsc --noEmit -p experiments/sqlite-lanes/tsconfig.json && tsc --noEmit -p experiments/lane-pool/tsconfig.json && tsc --noEmit -p experiments/continuation/tsconfig.json && bun scripts/docs/fences.ts",
|
|
81
66
|
"typecheck:php": "node experiments/consumer/php/prepare.ts && tsc --noEmit -p experiments/consumer/php/tsconfig.json",
|
|
82
67
|
"typecheck:bootimage": "node experiments/bootimage/prepare.ts && tsc --noEmit -p experiments/bootimage/tsconfig.json",
|
|
83
68
|
"test": "vitest run --project unit",
|
|
@@ -88,7 +73,8 @@
|
|
|
88
73
|
"test:e2e": "vitest run --project e2e",
|
|
89
74
|
"example": "node examples/basic.ts",
|
|
90
75
|
"analyze": "bun scripts/analyze/run.ts",
|
|
91
|
-
"docs:build": "typedoc",
|
|
76
|
+
"docs:build": "typedoc && bun scripts/docs/nav.ts",
|
|
77
|
+
"docs:check": "bun scripts/docs/check.ts",
|
|
92
78
|
"docs:serve": "typedoc --watch",
|
|
93
79
|
"prettier": "prettier --write .",
|
|
94
80
|
"prettier:check": "prettier --check .",
|
|
@@ -99,20 +85,20 @@
|
|
|
99
85
|
"binaryen": "132.0.0"
|
|
100
86
|
},
|
|
101
87
|
"devDependencies": {
|
|
102
|
-
"@cloudflare/playwright": "1.
|
|
103
|
-
"@cloudflare/workers-types": "^5.
|
|
104
|
-
"@types/node": "^26.
|
|
105
|
-
"@vitest/coverage-v8": "^5.
|
|
88
|
+
"@cloudflare/playwright": "1.4.0",
|
|
89
|
+
"@cloudflare/workers-types": "^5.20261121.1",
|
|
90
|
+
"@types/node": "^26.6.6",
|
|
91
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
106
92
|
"esbuild": "0.28.2",
|
|
107
93
|
"husky": "^9.1.7",
|
|
108
|
-
"lint-staged": "^17.6.
|
|
109
|
-
"prettier": "^3.
|
|
94
|
+
"lint-staged": "^17.6.1",
|
|
95
|
+
"prettier": "^3.10.1",
|
|
110
96
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
111
97
|
"prettier-plugin-sh": "^0.20.2",
|
|
112
98
|
"typedoc": "^0.28.20",
|
|
113
99
|
"typescript": "^5.9.3",
|
|
114
|
-
"vitest": "^5.
|
|
115
|
-
"wrangler": "^4.
|
|
100
|
+
"vitest": "^5.1.1",
|
|
101
|
+
"wrangler": "^4.166.0"
|
|
116
102
|
},
|
|
117
103
|
"publishConfig": {
|
|
118
104
|
"access": "public"
|
package/dist/frames.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { decodeValue, encodeValue } from "./remote.js";
|
|
2
|
-
const magic = 0x314f4c46;
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
5
|
-
/** Encodes sparse arenas. A dense payload borrows the input until encodeFrame copies it. */
|
|
6
|
-
export function encodeSnapshot(bytes) {
|
|
7
|
-
if (bytes.length % 65536)
|
|
8
|
-
throw new RangeError('invalid snapshot page size');
|
|
9
|
-
const pages = [];
|
|
10
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
11
|
-
for (let offset = 0; offset < bytes.length; offset += 65536) {
|
|
12
|
-
for (let word = offset; word < offset + 65536; word += 4)
|
|
13
|
-
if (view.getUint32(word, true) !== 0) {
|
|
14
|
-
pages.push(offset / 65536);
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (pages.length > 4096 || pages.length * 65536 + pages.length * 8 + 64 >= bytes.length)
|
|
19
|
-
return { payload: bytes };
|
|
20
|
-
const payload = new Uint8Array(pages.length * 65536);
|
|
21
|
-
pages.forEach((page, index) => payload.set(bytes.subarray(page * 65536, (page + 1) * 65536), index * 65536));
|
|
22
|
-
return { snapshot: { memoryBytes: bytes.length, pages }, payload };
|
|
23
|
-
}
|
|
24
|
-
/** Checks sparse metadata before allocation or writes; returns the complete logical byte length. */
|
|
25
|
-
export function snapshotLength(snapshot, payload) {
|
|
26
|
-
if (snapshot === undefined)
|
|
27
|
-
return payload.length;
|
|
28
|
-
if (!Number.isSafeInteger(snapshot?.memoryBytes) ||
|
|
29
|
-
snapshot.memoryBytes < 0 ||
|
|
30
|
-
snapshot.memoryBytes % 65536 ||
|
|
31
|
-
!Array.isArray(snapshot.pages) ||
|
|
32
|
-
snapshot.pages.length * 65536 !== payload.length)
|
|
33
|
-
throw new TypeError('invalid sparse snapshot');
|
|
34
|
-
let previous = -1;
|
|
35
|
-
for (const page of snapshot.pages) {
|
|
36
|
-
if (!Number.isSafeInteger(page) || page <= previous || page * 65536 >= snapshot.memoryBytes)
|
|
37
|
-
throw new TypeError('invalid sparse snapshot page');
|
|
38
|
-
previous = page;
|
|
39
|
-
}
|
|
40
|
-
return snapshot.memoryBytes;
|
|
41
|
-
}
|
|
42
|
-
/** Restores a complete snapshot, clearing pages omitted by the sparse representation. */
|
|
43
|
-
export function restoreSnapshot(target, payload, snapshot) {
|
|
44
|
-
if (snapshotLength(snapshot, payload) !== target.length)
|
|
45
|
-
throw new RangeError('snapshot size differs');
|
|
46
|
-
if (!snapshot) {
|
|
47
|
-
target.set(payload);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
target.fill(0);
|
|
51
|
-
snapshot.pages.forEach((page, index) => target.set(payload.subarray(index * 65536, (index + 1) * 65536), page * 65536));
|
|
52
|
-
}
|
|
53
|
-
export function encodeFrame(header, payload = new Uint8Array(), maximum = 0x100100000) {
|
|
54
|
-
const metadata = encoder.encode(JSON.stringify(encodeValue(header)));
|
|
55
|
-
if (metadata.length > 65536)
|
|
56
|
-
throw new RangeError('frame header exceeds limit');
|
|
57
|
-
const length = 12 + metadata.length + payload.length;
|
|
58
|
-
if (payload.length > 0xffffffff || length > maximum)
|
|
59
|
-
throw new RangeError(`frame of ${length} bytes exceeds the limit of ${maximum} bytes`);
|
|
60
|
-
const bytes = new Uint8Array(length);
|
|
61
|
-
const view = new DataView(bytes.buffer);
|
|
62
|
-
view.setUint32(0, magic, true);
|
|
63
|
-
view.setUint32(4, metadata.length, true);
|
|
64
|
-
view.setUint32(8, payload.length, true);
|
|
65
|
-
bytes.set(metadata, 12);
|
|
66
|
-
bytes.set(payload, 12 + metadata.length);
|
|
67
|
-
return bytes;
|
|
68
|
-
}
|
|
69
|
-
export function decodeFrame(bytes, maximum) {
|
|
70
|
-
if (bytes.length < 12 || bytes.length > maximum)
|
|
71
|
-
throw new RangeError('invalid frame size');
|
|
72
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
73
|
-
const header = view.getUint32(4, true), payload = view.getUint32(8, true);
|
|
74
|
-
if (view.getUint32(0, true) !== magic ||
|
|
75
|
-
header > 65536 ||
|
|
76
|
-
12 + header + payload !== bytes.length)
|
|
77
|
-
throw new TypeError('invalid frame layout');
|
|
78
|
-
return {
|
|
79
|
-
header: decodeValue(JSON.parse(decoder.decode(bytes.subarray(12, 12 + header)))),
|
|
80
|
-
payload: bytes.subarray(12 + header)
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export function validateIdentity(value) {
|
|
84
|
-
if (typeof value?.session !== 'string' ||
|
|
85
|
-
value.session.length < 1 ||
|
|
86
|
-
value.session.length > 128 ||
|
|
87
|
-
!Number.isSafeInteger(value.epoch) ||
|
|
88
|
-
value.epoch < 0 ||
|
|
89
|
-
!Number.isSafeInteger(value.sequence) ||
|
|
90
|
-
value.sequence < 0)
|
|
91
|
-
throw new TypeError('invalid frame identity');
|
|
92
|
-
}
|
|
93
|
-
export function encodeResults(identity, results, maximum = 0x100100000) {
|
|
94
|
-
const length = results.reduce((sum, result) => sum + result.reads.length * 4 + result.writes.length * 8, 0);
|
|
95
|
-
if (length > 0xffffffff || length + 12 > maximum)
|
|
96
|
-
throw new RangeError('result payload exceeds limit');
|
|
97
|
-
const payload = new Uint8Array(length), view = new DataView(payload.buffer);
|
|
98
|
-
let offset = 0;
|
|
99
|
-
const descriptors = results.map(({ reads, writes, ...result }) => {
|
|
100
|
-
for (const address of reads) {
|
|
101
|
-
view.setUint32(offset, address, true);
|
|
102
|
-
offset += 4;
|
|
103
|
-
}
|
|
104
|
-
for (const [address, value] of writes) {
|
|
105
|
-
view.setUint32(offset, address, true);
|
|
106
|
-
view.setUint32(offset + 4, value, true);
|
|
107
|
-
offset += 8;
|
|
108
|
-
}
|
|
109
|
-
return { ...result, reads: reads.length, writes: writes.length };
|
|
110
|
-
});
|
|
111
|
-
return encodeFrame({
|
|
112
|
-
session: identity.session,
|
|
113
|
-
epoch: identity.epoch,
|
|
114
|
-
sequence: identity.sequence,
|
|
115
|
-
results: descriptors
|
|
116
|
-
}, payload, maximum);
|
|
117
|
-
}
|
|
118
|
-
export function decodeResults(bytes, identity, options) {
|
|
119
|
-
const { header, payload } = decodeFrame(bytes, options.maximumFrameBytes);
|
|
120
|
-
validateIdentity(header);
|
|
121
|
-
if (header.session !== identity.session ||
|
|
122
|
-
header.epoch !== identity.epoch ||
|
|
123
|
-
header.sequence !== identity.sequence)
|
|
124
|
-
throw new TypeError('stale lane response');
|
|
125
|
-
if (!Array.isArray(header.results) || header.results.length !== options.calls)
|
|
126
|
-
throw new TypeError('invalid lane result count');
|
|
127
|
-
let offset = 0, retained = 0;
|
|
128
|
-
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
129
|
-
const results = header.results.map(({ reads, writes, ...result }) => {
|
|
130
|
-
if (![reads, writes].every((n) => Number.isSafeInteger(n) && n >= 0))
|
|
131
|
-
throw new TypeError('invalid lane tracking counts');
|
|
132
|
-
retained += reads + writes;
|
|
133
|
-
if (retained > options.maxBytes + 8 || offset + reads * 4 + writes * 8 > payload.length)
|
|
134
|
-
throw new RangeError('lane tracking exceeds limit');
|
|
135
|
-
if ((result.trap !== undefined && typeof result.trap !== 'string') ||
|
|
136
|
-
(result.errorKind !== undefined && typeof result.errorKind !== 'string') ||
|
|
137
|
-
(result.exhausted !== undefined && typeof result.exhausted !== 'boolean'))
|
|
138
|
-
throw new TypeError('invalid lane trap');
|
|
139
|
-
const readSet = [], writeSet = [];
|
|
140
|
-
for (let i = 0; i < reads; i++) {
|
|
141
|
-
const address = view.getUint32(offset, true);
|
|
142
|
-
offset += 4;
|
|
143
|
-
if (address >= options.memoryBytes)
|
|
144
|
-
throw new RangeError('lane read outside arena');
|
|
145
|
-
readSet.push(address);
|
|
146
|
-
}
|
|
147
|
-
for (let i = 0; i < writes; i++) {
|
|
148
|
-
const address = view.getUint32(offset, true), value = view.getUint32(offset + 4, true);
|
|
149
|
-
offset += 8;
|
|
150
|
-
if (address >= options.memoryBytes || value > 255)
|
|
151
|
-
throw new RangeError('lane write outside arena');
|
|
152
|
-
writeSet.push([address, value]);
|
|
153
|
-
}
|
|
154
|
-
return { ...result, reads: readSet, writes: writeSet };
|
|
155
|
-
});
|
|
156
|
-
if (offset !== payload.length)
|
|
157
|
-
throw new TypeError('unconsumed lane payload');
|
|
158
|
-
return results;
|
|
159
|
-
}
|
package/dist/inline.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/** Names of the exported mutable i32 globals the inline lowering adds, plus the stack export. */
|
|
2
|
-
export declare const inlineGlobals: {
|
|
3
|
-
readonly readBitmap: "__folio_rb";
|
|
4
|
-
readonly writeBitmap: "__folio_wb";
|
|
5
|
-
readonly logPointer: "__folio_lp";
|
|
6
|
-
readonly logLimit: "__folio_ll";
|
|
7
|
-
readonly stampAddress: "__folio_sa";
|
|
8
|
-
readonly stackPointer: "__folio_sp";
|
|
9
|
-
readonly frameLow: "__folio_fl";
|
|
10
|
-
readonly frameSize: "__folio_fn";
|
|
11
|
-
readonly frameShadow: "__folio_fs";
|
|
12
|
-
};
|
|
13
|
-
/** Bytes of one undo entry: the granule address, the stamp, then the prior bytes of the granule. */
|
|
14
|
-
export declare const inlineEntryBytes: (writeGranule?: number) => number;
|
|
15
|
-
/** Options for `lowerInline`. */
|
|
16
|
-
export interface InlineOptions {
|
|
17
|
-
/** Read granule in bytes, a power of two from 16 to 4096. Default 64. */
|
|
18
|
-
readGranule?: number;
|
|
19
|
-
/** Write and undo granule in bytes, a power of two from 16 to 256. Default 32. */
|
|
20
|
-
writeGranule?: number;
|
|
21
|
-
/** Refuse a memory that is not shared. Pass false to lower a module for one thread. Default true. */
|
|
22
|
-
requireShared?: boolean;
|
|
23
|
-
/** The mutable i32 global exported as `__folio_sp`. Default: the one `stackRoute` names, if any. */
|
|
24
|
-
stack?: string;
|
|
25
|
-
/** Track exposed reads of one frame region (see `lowerInline`). Default off. */
|
|
26
|
-
frame?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A second lowering, next to the host-call one in `prepare`: it marks memory accesses inline, with
|
|
30
|
-
* no host call and no added import, so a region can be validated after it ran. Nothing in
|
|
31
|
-
* `prepare` calls it yet and its output is not a `PreparedProgram` field.
|
|
32
|
-
*
|
|
33
|
-
* State lives in mutable i32 globals the owner exports and sets before each region; all start at
|
|
34
|
-
* 0, which traps on the first access. `__folio_rb` and `__folio_wb` are the bases of the read and
|
|
35
|
-
* write bitmaps, `__folio_lp` and `__folio_ll` the undo log pointer and limit, `__folio_sa` the
|
|
36
|
-
* address of a shared i32 stamp counter (4-byte aligned). The stack pointer global is exported as
|
|
37
|
-
* `__folio_sp` when the module has one. A bitmap has one bit per granule: granule `g`, with
|
|
38
|
-
* `g = address >> log2(granule)`, is bit `g & 7` of byte `base + (g >> 3)`. The bitmaps are
|
|
39
|
-
* private to a region and the owner clears them between regions.
|
|
40
|
-
*
|
|
41
|
-
* Every load, store, atomic access and SIMD load marks its read granule, and an access that
|
|
42
|
-
* crosses a boundary marks both. A store, a SIMD lane store and the destination of `memory.copy`,
|
|
43
|
-
* `memory.fill` and `memory.init` mark write granules; atomic accesses mark both sets; the source
|
|
44
|
-
* of `memory.copy` marks read granules. The first write to a write granule appends an undo entry
|
|
45
|
-
* at `__folio_lp`: the granule address (u32), a stamp from an atomic add on `__folio_sa` taken
|
|
46
|
-
* after the prior bytes were copied and before the write, then the prior bytes of the granule.
|
|
47
|
-
* `__folio_lp` then advances by `inlineEntryBytes(writeGranule)`; an entry that would pass
|
|
48
|
-
* `__folio_ll` traps with `unreachable`. The start function is not lowered.
|
|
49
|
-
*
|
|
50
|
-
* With `frame: true` the module also tracks one frame region, for a stack frame whose bytes an
|
|
51
|
-
* iteration may read after an earlier iteration wrote them. The owner sets `__folio_fl` (low
|
|
52
|
-
* address), `__folio_fn` (size in bytes) and `__folio_fs` (shadow base) before a region; with
|
|
53
|
-
* `__folio_fn` at 0 nothing is tracked. An access that overlaps the region is checked against a
|
|
54
|
-
* shadow of one written bit per frame byte, `4 * ceil(size / 32)` bytes with the bits of frame
|
|
55
|
-
* granule `g` (32 bytes) in the i32 at `__folio_fs + 4 * g`, then 4 pad bytes, then the exposed
|
|
56
|
-
* bits laid out the same way, then 4 more pad bytes. A store sets written bits after its value is
|
|
57
|
-
* computed; a load sets the exposed bit of each byte it reads whose written bit is clear, so a
|
|
58
|
-
* region reports exactly the frame bytes it read before it wrote them.
|
|
59
|
-
* `memory.copy`, `memory.fill` and `memory.init` set or check the exact byte range, an atomic
|
|
60
|
-
* read-modify-write checks then sets, and any other atomic access or SIMD load checks. The owner
|
|
61
|
-
* zeroes the shadow before each region. Accesses outside the region pay one compare. Stack below
|
|
62
|
-
* the region is not tracked.
|
|
63
|
-
*
|
|
64
|
-
* Throws for a module without exactly one memory, a 64-bit memory, an unshared memory when
|
|
65
|
-
* `requireShared` is set, a start function that calls, a reserved name or an expression it does
|
|
66
|
-
* not know. An imported host function that touches memory is not seen.
|
|
67
|
-
*/
|
|
68
|
-
export declare function lowerInline(bytes: Uint8Array, options?: InlineOptions): Uint8Array;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/** Why the rest of a loop ran serially after the pooled path was tried or refused. */
|
|
2
|
-
export type IterationStop = 'no-admission' | 'log-exhausted' | 'frame-carried dependence' | 'dependency';
|
|
3
|
-
/** What the admission decision saw and chose for one owner call's loop. */
|
|
4
|
-
export interface IterationAdmission {
|
|
5
|
-
/** Time of iteration 0 on the owner thread, on a plain instance and the real frame. */
|
|
6
|
-
plainIterationMs: number;
|
|
7
|
-
/** Serial time of the iterations after iteration 0, from `plainIterationMs`. */
|
|
8
|
-
remainingSerialMs: number;
|
|
9
|
-
/** The least remaining serial time worth dispatching: `fixedMs * margin`. */
|
|
10
|
-
floorMs: number;
|
|
11
|
-
/** The decision before the first dispatch. A later stop is `IterationReport.stopped`. */
|
|
12
|
-
admitted: boolean;
|
|
13
|
-
/** Wall of the last batch, dispatch to the end of its replays. */
|
|
14
|
-
batchWallMs?: number;
|
|
15
|
-
/** The same iterations at `plainIterationMs` each. */
|
|
16
|
-
batchSerialMs?: number;
|
|
17
|
-
}
|
|
18
|
-
/** The constants of the decision. A re-calibration changes these and nothing else. */
|
|
19
|
-
export interface IterationAdmissionConstants {
|
|
20
|
-
/** Wall of the pooled path that does not shrink with the loop: dispatch, join, validation. */
|
|
21
|
-
fixedMs: number;
|
|
22
|
-
/** The pooled path has to beat the serial one by this factor, before and after each batch. */
|
|
23
|
-
margin: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Fitted on a Mac sweep of `scripts/research/iteration-admission.ts` and checked on the rig at widths
|
|
27
|
-
* 8 and 4; a re-calibration updates only these two numbers.
|
|
28
|
-
*
|
|
29
|
-
* `fixedMs` 2 is the smallest value at which no cell of the Mac sweep (18 cells, 4 KiB to 4 MiB
|
|
30
|
-
* by 8 to 128 iterations, width 8) dispatched and lost. The pooled wall minus the batch time
|
|
31
|
-
* measured 0.1 to 2.9 ms there with the input copy left out of the timing; the prototype's rows
|
|
32
|
-
* bracket 3 to 8 ms but include that copy. The loop is not worth dispatching when the serial time
|
|
33
|
-
* of its remaining iterations is below `fixedMs * margin`.
|
|
34
|
-
*
|
|
35
|
-
* `margin` 1.25 is the speedup a batch has to show over the serial time of its iterations for
|
|
36
|
-
* the loop to keep dispatching. A batch that misses it twice in a row ends the dispatch, and so
|
|
37
|
-
* does one batch whose wall passes `batchCollapse` times that serial time.
|
|
38
|
-
*/
|
|
39
|
-
export declare const iterationAdmissionConstants: IterationAdmissionConstants;
|
|
40
|
-
export interface AdmitInput {
|
|
41
|
-
plainIterationMs: number;
|
|
42
|
-
trip: number;
|
|
43
|
-
width: number;
|
|
44
|
-
constants?: IterationAdmissionConstants;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Decides before the first dispatch from the measured serial time of iteration 0, which has
|
|
48
|
-
* already run. Admits when at least two iterations are left for at least two workers and their
|
|
49
|
-
* serial time exceeds `fixedMs * margin`. Whether dispatch pays is then checked per batch.
|
|
50
|
-
*/
|
|
51
|
-
export declare function admitIteration({ plainIterationMs: t0, trip, width, constants }: AdmitInput): IterationAdmission;
|
|
52
|
-
/** True when a batch did not beat the serial time of its iterations by the margin. */
|
|
53
|
-
export declare function batchLoses(batchWallMs: number, batchSerialMs: number, constants?: IterationAdmissionConstants): boolean;
|
|
54
|
-
/** Batch wall over serial time past which one batch is a verdict, with no second batch to confirm. */
|
|
55
|
-
export declare const batchCollapse = 1.5;
|
|
56
|
-
/** True when a batch took clearly longer than the serial time of its iterations. */
|
|
57
|
-
export declare function batchCollapses(batchWallMs: number, batchSerialMs: number): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Test and sweep seam, module state and not an option. `scale` multiplies the measured time of
|
|
60
|
-
* iteration 0 before the first decision and `batchScale` the wall of each batch before the batch
|
|
61
|
-
* rule; `force` admits any loop with an iteration left after iteration 0 and never stops on the
|
|
62
|
-
* batch rule. The structural stops (`log-exhausted`, `frame-carried dependence`, `dependency`)
|
|
63
|
-
* are not affected.
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
export declare const admissionSeam: {
|
|
67
|
-
scale: number;
|
|
68
|
-
batchScale: number;
|
|
69
|
-
force: boolean;
|
|
70
|
-
};
|
|
71
|
-
/** `admitIteration` through the seam; what the host function calls. */
|
|
72
|
-
export declare function decideAdmission(plainIterationMs: number, trip: number, width: number): IterationAdmission;
|
|
73
|
-
/** `batchLoses` through the seam; what the host function passes the pool. */
|
|
74
|
-
export declare function decideBatch(batchWallMs: number, batchSerialMs: number): boolean;
|
|
75
|
-
/** `batchCollapses` through the seam; what the host function passes the pool. */
|
|
76
|
-
export declare function decideCollapse(batchWallMs: number, batchSerialMs: number): boolean;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fitted on a Mac sweep of `scripts/research/iteration-admission.ts` and checked on the rig at widths
|
|
3
|
-
* 8 and 4; a re-calibration updates only these two numbers.
|
|
4
|
-
*
|
|
5
|
-
* `fixedMs` 2 is the smallest value at which no cell of the Mac sweep (18 cells, 4 KiB to 4 MiB
|
|
6
|
-
* by 8 to 128 iterations, width 8) dispatched and lost. The pooled wall minus the batch time
|
|
7
|
-
* measured 0.1 to 2.9 ms there with the input copy left out of the timing; the prototype's rows
|
|
8
|
-
* bracket 3 to 8 ms but include that copy. The loop is not worth dispatching when the serial time
|
|
9
|
-
* of its remaining iterations is below `fixedMs * margin`.
|
|
10
|
-
*
|
|
11
|
-
* `margin` 1.25 is the speedup a batch has to show over the serial time of its iterations for
|
|
12
|
-
* the loop to keep dispatching. A batch that misses it twice in a row ends the dispatch, and so
|
|
13
|
-
* does one batch whose wall passes `batchCollapse` times that serial time.
|
|
14
|
-
*/
|
|
15
|
-
export const iterationAdmissionConstants = {
|
|
16
|
-
fixedMs: 2,
|
|
17
|
-
margin: 1.25
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Decides before the first dispatch from the measured serial time of iteration 0, which has
|
|
21
|
-
* already run. Admits when at least two iterations are left for at least two workers and their
|
|
22
|
-
* serial time exceeds `fixedMs * margin`. Whether dispatch pays is then checked per batch.
|
|
23
|
-
*/
|
|
24
|
-
export function admitIteration({ plainIterationMs: t0, trip, width, constants = iterationAdmissionConstants }) {
|
|
25
|
-
const remaining = trip - 1;
|
|
26
|
-
const remainingSerialMs = remaining * t0;
|
|
27
|
-
const floorMs = constants.fixedMs * constants.margin;
|
|
28
|
-
const admitted = Number.isFinite(t0) && remaining >= 2 && width >= 2 && remainingSerialMs > floorMs;
|
|
29
|
-
return { plainIterationMs: t0, remainingSerialMs, floorMs, admitted };
|
|
30
|
-
}
|
|
31
|
-
/** True when a batch did not beat the serial time of its iterations by the margin. */
|
|
32
|
-
export function batchLoses(batchWallMs, batchSerialMs, constants = iterationAdmissionConstants) {
|
|
33
|
-
return batchWallMs * constants.margin > batchSerialMs;
|
|
34
|
-
}
|
|
35
|
-
/** Batch wall over serial time past which one batch is a verdict, with no second batch to confirm. */
|
|
36
|
-
export const batchCollapse = 1.5;
|
|
37
|
-
/** True when a batch took clearly longer than the serial time of its iterations. */
|
|
38
|
-
export function batchCollapses(batchWallMs, batchSerialMs) {
|
|
39
|
-
return batchWallMs > batchSerialMs * batchCollapse;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Test and sweep seam, module state and not an option. `scale` multiplies the measured time of
|
|
43
|
-
* iteration 0 before the first decision and `batchScale` the wall of each batch before the batch
|
|
44
|
-
* rule; `force` admits any loop with an iteration left after iteration 0 and never stops on the
|
|
45
|
-
* batch rule. The structural stops (`log-exhausted`, `frame-carried dependence`, `dependency`)
|
|
46
|
-
* are not affected.
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export const admissionSeam = { scale: 1, batchScale: 1, force: false };
|
|
50
|
-
/** `admitIteration` through the seam; what the host function calls. */
|
|
51
|
-
export function decideAdmission(plainIterationMs, trip, width) {
|
|
52
|
-
const decision = admitIteration({
|
|
53
|
-
plainIterationMs: plainIterationMs * admissionSeam.scale,
|
|
54
|
-
trip,
|
|
55
|
-
width
|
|
56
|
-
});
|
|
57
|
-
if (admissionSeam.force && trip >= 2 && width >= 2)
|
|
58
|
-
decision.admitted = true;
|
|
59
|
-
return decision;
|
|
60
|
-
}
|
|
61
|
-
/** `batchLoses` through the seam; what the host function passes the pool. */
|
|
62
|
-
export function decideBatch(batchWallMs, batchSerialMs) {
|
|
63
|
-
if (admissionSeam.force)
|
|
64
|
-
return false;
|
|
65
|
-
return batchLoses(batchWallMs * admissionSeam.batchScale, batchSerialMs);
|
|
66
|
-
}
|
|
67
|
-
/** `batchCollapses` through the seam; what the host function passes the pool. */
|
|
68
|
-
export function decideCollapse(batchWallMs, batchSerialMs) {
|
|
69
|
-
if (admissionSeam.force)
|
|
70
|
-
return false;
|
|
71
|
-
return batchCollapses(batchWallMs * admissionSeam.batchScale, batchSerialMs);
|
|
72
|
-
}
|
package/dist/iteration-worker.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import { iterationArguments, iterationEntryBytes } from "./iteration-layout.js";
|
|
3
|
-
const { module, memory, arena, globals, iterate, locals, frameSize, port, signal, control } = workerData;
|
|
4
|
-
const L = arena;
|
|
5
|
-
const ENTRY = iterationEntryBytes;
|
|
6
|
-
const exportsOf = new WebAssembly.Instance(module, { env: { memory } }).exports;
|
|
7
|
-
const u8 = new Uint8Array(memory.buffer);
|
|
8
|
-
const u32 = new Uint32Array(memory.buffer);
|
|
9
|
-
const counter = new Int32Array(control);
|
|
10
|
-
const done = new Int32Array(signal);
|
|
11
|
-
const now = () => performance.now();
|
|
12
|
-
const stats = { run: 0, scan: 0 };
|
|
13
|
-
// reads a bitmap into [start, length] runs of granules and zeroes it as it goes
|
|
14
|
-
function scan(base, size) {
|
|
15
|
-
const words = new Uint32Array(memory.buffer, base, size / 4);
|
|
16
|
-
const runs = [];
|
|
17
|
-
let start = -1;
|
|
18
|
-
for (let k = 0; k < words.length; k++) {
|
|
19
|
-
const w = words[k];
|
|
20
|
-
if (w === 0) {
|
|
21
|
-
if (start >= 0) {
|
|
22
|
-
runs.push(start, k * 32 - start);
|
|
23
|
-
start = -1;
|
|
24
|
-
}
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
words[k] = 0;
|
|
28
|
-
if (w === 0xffffffff) {
|
|
29
|
-
if (start < 0)
|
|
30
|
-
start = k * 32;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
for (let b = 0; b < 32; b++) {
|
|
34
|
-
if ((w >>> b) & 1) {
|
|
35
|
-
if (start < 0)
|
|
36
|
-
start = k * 32 + b;
|
|
37
|
-
}
|
|
38
|
-
else if (start >= 0) {
|
|
39
|
-
runs.push(start, k * 32 + b - start);
|
|
40
|
-
start = -1;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (start >= 0)
|
|
45
|
-
runs.push(start, words.length * 32 - start);
|
|
46
|
-
return Int32Array.from(runs);
|
|
47
|
-
}
|
|
48
|
-
// status 0 ran, 1 trapped, 2 undo log exhausted
|
|
49
|
-
function runOne(job, s) {
|
|
50
|
-
const index = job.first + s;
|
|
51
|
-
const top = L.slots + (s + 1) * L.slotBytes;
|
|
52
|
-
const frame = top - frameSize;
|
|
53
|
-
if (frameSize)
|
|
54
|
-
u8.copyWithin(frame, job.frameBase, job.frameBase + frameSize);
|
|
55
|
-
const shadow = L.frameShadow + s * L.frameSlotBytes;
|
|
56
|
-
if (frameSize) {
|
|
57
|
-
u8.fill(0, shadow, shadow + L.frameSlotBytes);
|
|
58
|
-
exportsOf[globals.frameLow].value = frame;
|
|
59
|
-
exportsOf[globals.frameSize].value = frameSize;
|
|
60
|
-
exportsOf[globals.frameShadow].value = shadow;
|
|
61
|
-
}
|
|
62
|
-
const rbase = L.rmaps + s * L.rsize;
|
|
63
|
-
const wbase = L.wmaps + s * L.wsize;
|
|
64
|
-
const lbase = L.logs + s * L.logBytes;
|
|
65
|
-
const limit = lbase + L.logCapacity * ENTRY;
|
|
66
|
-
exportsOf[globals.readBitmap].value = rbase;
|
|
67
|
-
exportsOf[globals.writeBitmap].value = wbase;
|
|
68
|
-
exportsOf[globals.logPointer].value = lbase;
|
|
69
|
-
exportsOf[globals.logLimit].value = limit;
|
|
70
|
-
exportsOf[globals.stampAddress].value = L.stamp;
|
|
71
|
-
const stack = exportsOf[globals.stackPointer];
|
|
72
|
-
if (stack)
|
|
73
|
-
stack.value = frameSize ? frame : top;
|
|
74
|
-
const args = iterationArguments(locals, job.entry, index, frame);
|
|
75
|
-
const t1 = now();
|
|
76
|
-
let status = 0;
|
|
77
|
-
try {
|
|
78
|
-
exportsOf[iterate](...args);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
const left = limit - (exportsOf[globals.logPointer].value >>> 0);
|
|
82
|
-
status =
|
|
83
|
-
error instanceof WebAssembly.RuntimeError &&
|
|
84
|
-
/unreachable/.test(error.message) &&
|
|
85
|
-
left < ENTRY
|
|
86
|
-
? 2
|
|
87
|
-
: 1;
|
|
88
|
-
}
|
|
89
|
-
const t2 = now();
|
|
90
|
-
stats.run += t2 - t1;
|
|
91
|
-
const entries = ((exportsOf[globals.logPointer].value >>> 0) - lbase) / ENTRY;
|
|
92
|
-
const written = new Int32Array(entries);
|
|
93
|
-
for (let e = 0; e < entries; e++)
|
|
94
|
-
written[e] = u32[(lbase + e * ENTRY) / 4] >>> 5;
|
|
95
|
-
written.sort();
|
|
96
|
-
const reads = scan(rbase, L.rsize);
|
|
97
|
-
let frameWritten = new Uint32Array(0);
|
|
98
|
-
let frameExposed = new Uint32Array(0);
|
|
99
|
-
if (frameSize) {
|
|
100
|
-
const granules = Math.ceil(frameSize / 32);
|
|
101
|
-
const words = (at) => u32.slice(at / 4, at / 4 + granules);
|
|
102
|
-
const copy = (at) => {
|
|
103
|
-
const found = words(at);
|
|
104
|
-
return found.some(Boolean) ? found : new Uint32Array(0);
|
|
105
|
-
};
|
|
106
|
-
frameWritten = copy(shadow);
|
|
107
|
-
frameExposed = copy(shadow + 4 * granules + 4);
|
|
108
|
-
}
|
|
109
|
-
if (status)
|
|
110
|
-
u8.fill(0, wbase, wbase + L.wsize);
|
|
111
|
-
else
|
|
112
|
-
for (let e = 0; e < entries; e++)
|
|
113
|
-
u8[wbase + (written[e] >>> 3)] = 0;
|
|
114
|
-
stats.scan += now() - t2;
|
|
115
|
-
return {
|
|
116
|
-
index,
|
|
117
|
-
status,
|
|
118
|
-
entries,
|
|
119
|
-
written,
|
|
120
|
-
reads,
|
|
121
|
-
frameWritten,
|
|
122
|
-
frameExposed
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
port.on('message', (job) => {
|
|
126
|
-
stats.run = 0;
|
|
127
|
-
stats.scan = 0;
|
|
128
|
-
let reply;
|
|
129
|
-
try {
|
|
130
|
-
const results = [];
|
|
131
|
-
for (;;) {
|
|
132
|
-
const k = Atomics.add(counter, 0, 1);
|
|
133
|
-
if (k >= job.count)
|
|
134
|
-
break;
|
|
135
|
-
const outcome = runOne(job, job.reverse ? job.count - 1 - k : k);
|
|
136
|
-
results.push(outcome);
|
|
137
|
-
// every later iteration is rolled back and replayed anyway, so leave them unstarted
|
|
138
|
-
if (outcome.status && !job.reverse)
|
|
139
|
-
Atomics.store(counter, 0, 1 << 30);
|
|
140
|
-
}
|
|
141
|
-
reply = { done: results, runMs: stats.run, scanMs: stats.scan };
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
reply = { error: String(error?.stack ?? error) };
|
|
145
|
-
}
|
|
146
|
-
port.postMessage(reply);
|
|
147
|
-
Atomics.add(done, 0, 1);
|
|
148
|
-
Atomics.notify(done, 0);
|
|
149
|
-
});
|
|
150
|
-
parentPort.postMessage({ ready: true });
|