@gmitch215/folio 1.1.0 → 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 +78 -810
- 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} +5 -5
- package/dist/{extract.d.ts → execution/extract.d.ts} +3 -13
- package/dist/{extract.js → execution/extract.js} +7 -8
- package/dist/{fold.d.ts → execution/fold.d.ts} +15 -3
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/types.d.ts +221 -0
- package/dist/{affine-state.d.ts → folds/affine-state.d.ts} +18 -47
- package/dist/{affine-state.js → folds/affine-state.js} +18 -44
- package/dist/{affine.d.ts → folds/affine.d.ts} +12 -24
- package/dist/{affine.js → folds/affine.js} +8 -17
- package/dist/{boundaries.d.ts → folds/boundaries.d.ts} +7 -18
- package/dist/{boundaries.js → folds/boundaries.js} +5 -13
- package/dist/{certified.d.ts → folds/certified.d.ts} +13 -24
- package/dist/{certified.js → folds/certified.js} +12 -26
- package/dist/{certify.d.ts → folds/certify.d.ts} +11 -22
- package/dist/{certify.js → folds/certify.js} +24 -41
- package/dist/{memo.d.ts → footprints/memo.d.ts} +8 -33
- package/dist/{memo.js → footprints/memo.js} +8 -2
- package/dist/{ranges.js → footprints/ranges.js} +1 -1
- package/dist/{read-scan.js → footprints/read-scan.js} +1 -1
- package/dist/{read-windows.d.ts → footprints/read-windows.d.ts} +6 -32
- package/dist/{read-windows.js → footprints/read-windows.js} +8 -7
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/{iteration-admission.d.ts → iteration/admission.d.ts} +2 -38
- package/dist/{iteration.d.ts → iteration/index.d.ts} +8 -98
- package/dist/{iteration.js → iteration/index.js} +28 -28
- package/dist/{inline.js → iteration/inline.js} +2 -9
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +3 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +4 -3
- package/dist/{iteration-worker.js → iteration/worker.js} +3 -3
- package/dist/{managed.d.ts → managed/index.d.ts} +3 -3
- package/dist/{managed.js → managed/index.js} +7 -9
- 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} +1 -1
- 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} +1 -1
- 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} +4 -49
- package/dist/{node.js → node/index.js} +16 -17
- package/dist/{tasks.d.ts → node/tasks.d.ts} +2 -13
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/{ownership.js → ownership/index.js} +7 -10
- package/dist/{ownership-redirect.d.ts → ownership/redirect.d.ts} +2 -2
- package/dist/{ownership-redirect.js → ownership/redirect.js} +2 -2
- package/dist/{ownership-slices.d.ts → ownership/slices.d.ts} +3 -3
- package/dist/{ownership-slices.js → ownership/slices.js} +3 -3
- package/dist/{frames.d.ts → remote/frames.d.ts} +1 -1
- package/dist/{frames.js → remote/frames.js} +2 -2
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/{router.d.ts → routing/index.d.ts} +3 -3
- package/dist/{router.js → routing/index.js} +19 -15
- package/dist/{router-worker.js → routing/worker.js} +1 -1
- package/dist/{slices.d.ts → slices/index.d.ts} +2 -2
- package/dist/{slices.js → slices/index.js} +5 -5
- package/dist/slices/worker.d.ts +1 -0
- package/dist/{slices-worker.js → slices/worker.js} +2 -2
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +30 -80
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.js} +0 -0
- /package/dist/{fold.js → execution/fold.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/{runs.d.ts → execution/runs.d.ts} +0 -0
- /package/dist/{runs.js → execution/runs.js} +0 -0
- /package/dist/{transaction.d.ts → execution/transaction.d.ts} +0 -0
- /package/dist/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{ranges.d.ts → footprints/ranges.d.ts} +0 -0
- /package/dist/{read-scan.d.ts → footprints/read-scan.d.ts} +0 -0
- /package/dist/{iteration-admission.js → iteration/admission.js} +0 -0
- /package/dist/{inline.d.ts → iteration/inline.d.ts} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{iteration-layout.js → memory/iteration-layout.js} +0 -0
- /package/dist/{lease.d.ts → memory/lease.d.ts} +0 -0
- /package/dist/{lease.js → memory/lease.js} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{context.js → node/context.js} +0 -0
- /package/dist/{tasks.js → node/tasks.js} +0 -0
- /package/dist/{router-worker.d.ts → node/worker.d.ts} +0 -0
- /package/dist/{ownership.d.ts → ownership/index.d.ts} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
- /package/dist/{slices-worker.d.ts → routing/worker.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# 🚋 Folio
|
|
2
2
|
|
|
3
|
-
> ⚡
|
|
3
|
+
> ⚡ WebAssembly tooling for Node, Workers and browsers
|
|
4
4
|
|
|
5
|
-
Folio
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Folio is a toolkit for running, resetting and bounding WebAssembly modules in JavaScript runtimes.
|
|
6
|
+
Its core runs native WebAssembly across several V8 isolates that share one physical memory
|
|
7
|
+
allocation. It finds inline memory regions and pure calls in ordinary programs, validates the ones
|
|
8
|
+
it cannot prove independent, and keeps the serial result. Around the core sit task and slice pools,
|
|
9
|
+
exact stream folds, instance checkpoints, baked boot images, a growth governor and a portable client
|
|
10
|
+
for workerd and managed Cloudflare Workers.
|
|
10
11
|
|
|
11
12
|
## Table of Contents
|
|
12
13
|
|
|
@@ -15,42 +16,31 @@ the same engine.
|
|
|
15
16
|
- [Install](#-install)
|
|
16
17
|
- [Getting Started](#-getting-started)
|
|
17
18
|
- [Examples](#-examples)
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [Managed Workers](#-managed-workers)
|
|
21
|
-
- [Browser Execution and Page Leases](#-browser-execution-and-page-leases)
|
|
22
|
-
- [Task Pool](#-task-pool)
|
|
23
|
-
- [Slice Pool](#-slice-pool)
|
|
24
|
-
- [Certified Stream Folds](#-certified-stream-folds)
|
|
25
|
-
- [Ownership Certificates](#-ownership-certificates)
|
|
26
|
-
- [Router](#-router)
|
|
27
|
-
- [Context Checkpoints](#-context-checkpoints)
|
|
28
|
-
- [Baked Boot Images](#-baked-boot-images)
|
|
29
|
-
- [Execution and Memory](#-execution-and-memory)
|
|
30
|
-
- [API Reference](#-api-reference)
|
|
31
|
-
- [Consumer Harness](#-consumer-harness)
|
|
32
|
-
- [Measured Results](#-measured-results)
|
|
19
|
+
- [Modules](#-modules)
|
|
20
|
+
- [Limits](#-limits)
|
|
33
21
|
- [Development](#-development)
|
|
34
22
|
- [Contributing](#-contributing)
|
|
35
23
|
- [License](#-license)
|
|
36
24
|
|
|
37
25
|
## 🧭 Why Folio
|
|
38
26
|
|
|
39
|
-
A Worker, a Linux machine in a Durable Object and a PHP interpreter all end up as one Wasm
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
A Worker, a Linux machine in a Durable Object and a PHP interpreter all end up as one Wasm instance
|
|
28
|
+
on one thread. Folio spreads the work of that instance across cores without asking the program to be
|
|
29
|
+
rewritten. The caller passes one ordinary entry point, and the compiler discovers the regions. The
|
|
30
|
+
task pool, slice pool and chunked recurrences take a caller declaration instead, and the report says
|
|
31
|
+
which checks each route runs. The same package manages the instance itself: it resets a private
|
|
32
|
+
instance between jobs, starts a module from a booted heap and refuses memory growth past a cap.
|
|
45
33
|
|
|
46
|
-
- **Native Sharing.** Isolates map the same backing allocation
|
|
47
|
-
|
|
34
|
+
- **Native Sharing.** Isolates map the same backing allocation. Four isolates attach to a touched 64
|
|
35
|
+
MiB backing for 3.871 MiB of additional resident memory, against 259.930 MiB for copied buffers.
|
|
48
36
|
- **Serial Semantics.** On the automatic routes, uncertain dependencies run on private overlays and
|
|
49
37
|
commit in original order. A conflict replays against committed state, and a trap keeps its
|
|
50
|
-
preceding writes.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
preceding writes.
|
|
39
|
+
- **Original Stack.** JSPI suspends the program's own Wasm stack at joins, so branches, scalar carry
|
|
40
|
+
and host effects behave as they do natively.
|
|
41
|
+
- **Instance Control.** Checkpoints restore a private instance between jobs, boot images start a
|
|
42
|
+
module from a booted memory, and the growth governor turns an oversized allocation into a failure
|
|
43
|
+
the guest can report.
|
|
54
44
|
- **Portable.** The client and the managed backend use fetch, WebSockets and Durable Objects, with
|
|
55
45
|
no Node imports and no request-time Wasm compilation.
|
|
56
46
|
|
|
@@ -59,32 +49,19 @@ and a small job loses to dispatch overhead.
|
|
|
59
49
|
|
|
60
50
|
## ✨ Features
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
stack per worker and an optional serial audit, for calls the caller declares independent.
|
|
76
|
-
- 🧮 **Exact chunked recurrences** that split one CRC-32, Adler-32 or AES-CTR stream across the
|
|
77
|
-
task pool and join the chunk states into the serial result.
|
|
78
|
-
- 🔏 **Ownership certificates** that check whether the fixed-address scratch of a record function is
|
|
79
|
-
private to each record, so a certified loop of records runs in place on the slice pool. Each
|
|
80
|
-
certificate lists the premises it relies on.
|
|
81
|
-
- 🚦 **Router** that picks the certified summary, the certified window, tracked speculation or
|
|
82
|
-
serial for each call, caches certificates and refusals, and names the reason for every refusal.
|
|
83
|
-
- 🛑 **Stall guard** (`iterationStall`, off by default) that stops an iteration batch that does not
|
|
84
|
-
return and finishes the loop serially, for programs whose iterations can loop on state another
|
|
85
|
-
iteration is changing.
|
|
86
|
-
- 🧊 **Baked boot images** that write a booted memory into the module as data segments.
|
|
87
|
-
- 📊 **Opt-in profiling** of worker time, validation, commit and replay cost.
|
|
52
|
+
| Feature | What it does | Module |
|
|
53
|
+
| --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
54
|
+
| Region discovery, ordered validation, native guards and asynchronous host effects | Runs one ordinary entry on several cores and keeps the serial result | [Core](docs/modules/core.md) |
|
|
55
|
+
| Task pool and slice pool | Run named tasks in private contexts, or slices of a call range in place on one shared memory | [Pools](docs/modules/pools.md) |
|
|
56
|
+
| Exact chunked recurrences and certified stream folds | Split one CRC-32, Adler-32 or AES-CTR stream across workers and join the chunk states | [Folds and Certificates](docs/modules/folds-and-certificates.md) |
|
|
57
|
+
| Ownership certificates and the router | Prove that a record loop keeps its scratch private, and pick a route per call with a stated reason | [Folds and Certificates](docs/modules/folds-and-certificates.md) |
|
|
58
|
+
| Execution host and instance checkpoints | Serve a program over an authenticated fetch handler, and restore a private instance between jobs | [Core](docs/modules/core.md) |
|
|
59
|
+
| Managed Workers and portable client | Run entirely in Workers and Durable Objects, with binary frames and learned byte ranges between lanes | [Workers](docs/modules/workers.md) |
|
|
60
|
+
| Browser backend | Attach Web Workers to one shared memory, with page leases for transports that copy bytes | [Browser](docs/modules/browser.md) |
|
|
61
|
+
| Growth governor, page directory and leases | Refuse `memory.grow` past a byte cap, and hold bounded resident pages | [Memory](docs/modules/memory.md) |
|
|
62
|
+
| Baked boot images | Write a booted memory into the module as data segments | [Boot](docs/modules/boot.md) |
|
|
63
|
+
| Continuations | Run a Wasm guest across Durable Object alarm events with page-hash checkpoints in SQLite | [Continuation](docs/modules/continuation.md) |
|
|
64
|
+
| Profiling and the consumer harness | Time worker, validation, commit and replay cost, and time any Wasm module against a native instance of it | [Core](docs/modules/core.md) |
|
|
88
65
|
|
|
89
66
|
## 📦 Install
|
|
90
67
|
|
|
@@ -95,7 +72,7 @@ npm install @gmitch215/folio
|
|
|
95
72
|
```
|
|
96
73
|
|
|
97
74
|
The Node backend needs Node 26 or later. Async host imports and the managed backend need WebAssembly
|
|
98
|
-
JSPI. The browser counted-loop backend works without JSPI
|
|
75
|
+
JSPI. The browser counted-loop backend works without JSPI, and page-owner transports are portable.
|
|
99
76
|
Builds from the main branch publish to the `snapshot` tag.
|
|
100
77
|
|
|
101
78
|
## 🚀 Getting Started
|
|
@@ -116,48 +93,16 @@ try {
|
|
|
116
93
|
```
|
|
117
94
|
|
|
118
95
|
`Folio.open(input, options)` accepts a `Uint8Array`, an `ArrayBuffer`, a `WebAssembly.Module` or the
|
|
119
|
-
result of `prepare(bytes)`.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
Prepared plans are trusted build artifacts.
|
|
125
|
-
|
|
126
|
-
A region runs on a worker only when its estimated work pays for dispatch, joining and validation.
|
|
127
|
-
`prepare` estimates each candidate in instruction units, charges 3,600 units for every tracked load
|
|
128
|
-
or store, and keeps the region at its owner below `minimumRegionWork` (200,000 by default, about
|
|
129
|
-
39 microseconds of native work on an Apple M2 Pro). A loop bounded by a constant uses that count, a
|
|
130
|
-
loop bounded by an untouched parameter or a countdown from one is checked against the arguments at
|
|
131
|
-
each call, and any other loop is assumed to run `assumedTripCount` times (1,000). A module with no
|
|
132
|
-
region above the threshold and no eligible loop gets no control plan and runs as the original Wasm, so
|
|
133
|
-
a small kernel, a memory-bound loop or a serial recurrence stays at native speed.
|
|
134
|
-
`minimumRegionWork: 0` admits every pure region. `folio.diagnostics` says why a plan was refused.
|
|
135
|
-
|
|
136
|
-
A function with one countdown loop whose iterations are calls, such as a program that hashes several
|
|
137
|
-
files, runs its iterations on workers when `memory` is a shared `WebAssembly.Memory`. Iterations write
|
|
138
|
-
in place on private stack slots, validate in order and replay serially on a conflict. The first iteration
|
|
139
|
-
runs on the owner, and its measured time and the time of each batch decide whether dispatch continues. A
|
|
140
|
-
loop that writes more per iteration than the undo log holds, or whose batches lose to the serial time,
|
|
141
|
-
finishes serially. With an unshared memory, or one the library cannot grow by the arena it needs, the run
|
|
142
|
-
stays serial and the report names the reason.
|
|
143
|
-
|
|
144
|
-
Five `Folio.open` options adjust the iteration route. All five are off by default.
|
|
145
|
-
|
|
146
|
-
| Option | Effect |
|
|
147
|
-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
148
|
-
| `iterationReadWindows` | Learns read windows from the first batch that finishes without a conflict, so loads of the input the iterations stream through set no per-access mark. A window can cost a false conflict, never a different result. |
|
|
149
|
-
| `iterationReadSummary` | Keeps a summary of the 64-word blocks of each read bitmap that a read touched, so workers scan those blocks and not the whole bitmap. The conflicts found do not change. It adds a few instructions to every tracked read. |
|
|
150
|
-
| `iterationSecondChance` | Judges a loop a little under the dispatch floor on one timed batch, and lets the batches a running loop has shown decide whether the rest pays. A probe that loses ends the dispatch and the loop runs serially for the next 16 calls. The result is the same either way. |
|
|
151
|
-
| `iterationLogCeiling` | A number of undo entries per iteration. When a batch exhausts the default log, the logs grow to this size and the batch retries once. Unset, that batch finishes serially. On padded LZ4 the retry cost more than the dispatch gained, because ordered validation is quadratic in the logged entries. |
|
|
152
|
-
| `iterationStall` | `true` or `{ factor, floorMs }`. Workers poll a stop word at every loop start. A batch that runs past `factor` times the serial time of its iterations (50 by default), and at least `floorMs` (2000 ms), traps and rolls back from the undo logs, and the loop finishes serially with `iteration.stopped` set to `stalled`. The poll cost 0.9% to 11.2% of worker time on the four programs measured. |
|
|
153
|
-
|
|
154
|
-
A program whose iterations can read state another iteration is changing and then loop on it, such as
|
|
155
|
-
a linked structure two iterations rewrite, needs `iterationStall`.
|
|
96
|
+
result of `prepare(bytes)`. `folio.run` returns a report that names the mode (`serial`,
|
|
97
|
+
`speculative` or `native-shared`), the workers that took part and the reason a call stayed serial. A
|
|
98
|
+
region runs on a worker only when its estimated work pays for dispatch, joining and validation, so a
|
|
99
|
+
small kernel, a memory-bound loop or a serial recurrence stays at native speed.
|
|
100
|
+
[Getting Started](docs/getting-started.md) walks through the report and the choice between routes.
|
|
156
101
|
|
|
157
102
|
## 🧩 Examples
|
|
158
103
|
|
|
159
|
-
The [examples](examples) run against the built
|
|
160
|
-
`bun run build:c` and `bun run build`:
|
|
104
|
+
The [examples](https://github.com/gmitch215/folio/tree/master/examples) run against the built
|
|
105
|
+
package with `node examples/<name>.ts` after `bun run build:c` and `bun run build`:
|
|
161
106
|
|
|
162
107
|
- `basic` runs one entry.
|
|
163
108
|
- `routing` reads the report and shows capped and adaptive routing.
|
|
@@ -168,718 +113,38 @@ The [examples](examples) run against the built package with `node examples/<name
|
|
|
168
113
|
- `slice-pool` fills one shared memory from several threads and audits the run against the serial
|
|
169
114
|
one.
|
|
170
115
|
- `boot-image` bakes captured memory into a module.
|
|
116
|
+
- `growth-governor` caps `memory.grow` on a guest's memory and shows the guest's failed allocation.
|
|
117
|
+
- `continuation` runs a guest across alarm events with checkpoints in storage.
|
|
171
118
|
|
|
172
|
-
|
|
119
|
+
[Advanced Usage](ADVANCED_USAGE.md) combines these for specialised cases.
|
|
173
120
|
|
|
174
|
-
|
|
175
|
-
import { Folio, suspending } from '@gmitch215/folio';
|
|
176
|
-
|
|
177
|
-
const folio = await Folio.open(module, {
|
|
178
|
-
imports: {
|
|
179
|
-
host: {
|
|
180
|
-
read: suspending(async (key) => (await fetch(new URL(String(key), storageUrl))).status)
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
promising: ['main']
|
|
184
|
-
});
|
|
185
|
-
const report = await folio.run('main', [42]);
|
|
186
|
-
await folio.close();
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
This needs a runtime with WebAssembly JSPI. Listed async exports and numeric-result coordinator
|
|
190
|
-
entries receive a promising wrapper. Reference-returning exports keep their native ABI, because
|
|
191
|
-
Promise assimilation would change an externref Promise's identity. Host effects run once in call
|
|
192
|
-
order and exceptions keep their identity. Opaque references stay in the original isolate. Closing
|
|
193
|
-
joins a suspended native call; it cannot cancel an arbitrary external Promise.
|
|
121
|
+
## 🗂️ Modules
|
|
194
122
|
|
|
195
|
-
|
|
123
|
+
Folio has six subpaths. Each one names a runtime boundary or a feature.
|
|
196
124
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
125
|
+
| Import | Runs on | Purpose | Page |
|
|
126
|
+
| ------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------- | -------------------------------------------- |
|
|
127
|
+
| `@gmitch215/folio` | Node | `Folio`, the compiler, folds, certificates, the router, task and slice pools, the execution host | [Core](docs/modules/core.md) |
|
|
128
|
+
| `@gmitch215/folio/workers` | Workers and Durable Objects | `ManagedFolio`, `FolioLane`, the remote client `RemoteFolio` and the frame and value codecs | [Workers](docs/modules/workers.md) |
|
|
129
|
+
| `@gmitch215/folio/browser` | Browsers without JSPI | `BrowserFolio`, which runs one counted-loop call on shared memory | [Browser](docs/modules/browser.md) |
|
|
130
|
+
| `@gmitch215/folio/memory` | Portable | Page directories and leases, the growth governor and elastic regions | [Memory](docs/modules/memory.md) |
|
|
131
|
+
| `@gmitch215/folio/boot` | Portable | Boot images: `bakeModule`, `captureImage`, `applyImage`, `checkBaked` and the image errors | [Boot](docs/modules/boot.md) |
|
|
132
|
+
| `@gmitch215/folio/continuation` | Portable | Wasm guests across Durable Object alarm events, with page-hash checkpoints in Durable Object SQLite | [Continuation](docs/modules/continuation.md) |
|
|
203
133
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
await remote.write(1024, inputBytes);
|
|
210
|
-
const report = await remote.run('program', [1024, wordCount, rounds]);
|
|
211
|
-
const output = await remote.read(1024, inputBytes.length);
|
|
212
|
-
} finally {
|
|
213
|
-
await remote.close();
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
The client runs in stock workerd with no Node imports and no runtime Wasm compilation. Requests and
|
|
218
|
-
results cross a serialized transport, and physical sharing happens inside the host. Each session
|
|
219
|
-
caches its last accepted result, so `retryPending()` recovers a lost response without repeating
|
|
220
|
-
effects. The cache is bounded and held in memory. Memory admission checks the initial accessible
|
|
221
|
-
backing, and trusted artifact factories enforce growth maxima and private-memory budgets.
|
|
222
|
-
|
|
223
|
-
## 📡 Managed Workers
|
|
224
|
-
|
|
225
|
-
`@gmitch215/folio/managed` exports `ManagedFolio` and `FolioLane` for execution entirely in managed
|
|
226
|
-
Workers and Durable Objects. `ManagedFolio` takes precompiled artifact modules and lane transports
|
|
227
|
-
whose `execute(frame)` returns a binary response, and `FolioLane` runs the tracked region module.
|
|
228
|
-
The original JSPI coordinator keeps control flow and host effects, and copied snapshots with
|
|
229
|
-
ordered byte validation connect independent lanes. A transport failure falls back to native owner
|
|
230
|
-
execution. Snapshot, frame, fuel and tracking bounds are configurable, and the canonical memory
|
|
231
|
-
must fit the owner runtime. Frames carry the whole snapshot by default. `snapshotEncoding: 'auto'`
|
|
232
|
-
omits pages that are all zero, which saves traffic for sparse arenas, and lanes older than 1.0.1
|
|
233
|
-
reject its frames. The snapshot limit is 31 MiB by default. A frame over `maximumFrameBytes` (the
|
|
234
|
-
snapshot limit plus 1 MiB, capped below the 32 MiB Workers RPC argument limit) is not sent: that
|
|
235
|
-
call runs at the owner and `diagnostics` names the frame size and the limit. See
|
|
236
|
-
[the managed procedure](experiments/managed/METHOD.md).
|
|
237
|
-
|
|
238
|
-
Four options change what a call costs. `ranges` ships the byte ranges a region reads and writes,
|
|
239
|
-
learned from earlier calls, instead of a snapshot: an 8 MiB arena sends about 0.2% of the bytes.
|
|
240
|
-
`inline` on a `FolioLane` runs a module that tracks accesses in its own code, so a lane no longer
|
|
241
|
-
calls back into JavaScript on every load and store. `runs: true` makes lanes answer in sorted byte
|
|
242
|
-
runs that the owner validates and commits as intervals. `memo` reuses a recorded result when the
|
|
243
|
-
bytes a region read are unchanged, through the same ordered validation. `fuel` bounds the
|
|
244
|
-
speculative back-edges of one call (100,000,000 by default); a call that runs out finishes serially
|
|
245
|
-
at the owner, so a long kernel needs a larger `fuel`.
|
|
246
|
-
|
|
247
|
-
Lane placement decides whether lanes overlap. Service-bound Worker lanes share a thread with their
|
|
248
|
-
caller, so four of them take as long as one lane run four times. Durable Object lanes run on their
|
|
249
|
-
own isolates and overlap. A decomposition that fits a managed lane is a few large explicit units
|
|
250
|
-
with a merge the caller declares, such as SQLite shards that each scan a row-id range; a loop of
|
|
251
|
-
small records does not pay for a lane call. The
|
|
252
|
-
[sharded SQLite probe](experiments/sqlite-lanes/README.md) runs 1,000,000-row queries 2.0x to 9.7x
|
|
253
|
-
faster than one object at four and eight shards, with every result equal to the serial one.
|
|
254
|
-
|
|
255
|
-
## 🔗 Browser Execution and Page Leases
|
|
256
|
-
|
|
257
|
-
`@gmitch215/folio/browser` exports `BrowserFolio` for Chromium and other hosts without JSPI. It
|
|
258
|
-
takes a precompiled original module and the `loops`, `native`, `reasons` and `memories` metadata
|
|
259
|
-
that `prepare` produced offline. `open()` attaches dedicated module workers to the supplied shared
|
|
260
|
-
memory. `run(name, args)` derives guarded partitions from one ordinary counted-loop call and joins
|
|
261
|
-
before it returns, with no snapshot and no runtime compiler. Other entries use the original owner.
|
|
262
|
-
The caller keeps exclusive ownership of the arena. A failure after native writes closes the pool,
|
|
263
|
-
and the application restores a checkpoint before retrying.
|
|
264
|
-
|
|
265
|
-
`@gmitch215/folio/pages` exports `PageDirectory`, `MemoryPageOwner`, `ResidentPageLease` and the
|
|
266
|
-
`PageOwner` transport contract. `acquire({ read, write })` obtains bounded resident pages and
|
|
267
|
-
`lease.view(page)` returns a private view of one. `commit()` stages immutable versions and
|
|
268
|
-
atomically publishes their manifest, `abort()` discards local changes, and `collect()` reclaims
|
|
269
|
-
retired versions with delayed-message fencing. The directory holds page metadata, not a whole heap.
|
|
270
|
-
|
|
271
|
-
Leases work on copied bytes, and the bundled owners and directory keep their state in memory. The
|
|
272
|
-
[technical report](TECHNICAL_REPORT.md) covers failure semantics, the native Wasm measurements and
|
|
273
|
-
the limits of both modules.
|
|
274
|
-
|
|
275
|
-
## 🧰 Task Pool
|
|
276
|
-
|
|
277
|
-
`@gmitch215/folio/tasks` runs independent work that a program names itself. A `TaskPool` owns one
|
|
278
|
-
channel per worker. The caller starts each worker with `pool.link(index)` and calls `serveTasks`
|
|
279
|
-
there with a function that runs a named task. The owner calls `submit(name, input)` and keeps going,
|
|
280
|
-
then `join(handle)` blocks until the output arrives, or `joinAsync(handle)` waits without blocking
|
|
281
|
-
the event loop. `run(jobs)` submits a list and returns the results in submission order, and
|
|
282
|
-
`runSync(jobs)` does the same where the caller cannot yield, such as inside a synchronous Wasm
|
|
283
|
-
import. Input and output are strings or bytes, `submitJson` and `result.json()` cover structured
|
|
284
|
-
values, and `pool.width` limits how many workers take tasks. Input on a `SharedArrayBuffer` is copied
|
|
285
|
-
at submit so a later write cannot reach the task. `submit`, `run` and `runSync` take `{ share: true }`
|
|
286
|
-
to post such an input as it is, which removes the copy when the caller promises not to write those
|
|
287
|
-
bytes until the task is joined.
|
|
288
|
-
|
|
289
|
-
```ts
|
|
290
|
-
import { Worker } from 'node:worker_threads';
|
|
291
|
-
import { TaskPool } from '@gmitch215/folio/tasks';
|
|
292
|
-
|
|
293
|
-
const pool = new TaskPool(4);
|
|
294
|
-
for (let index = 0; index < pool.size; index++) {
|
|
295
|
-
const link = pool.link(index);
|
|
296
|
-
new Worker(new URL('./task-worker.js', import.meta.url), {
|
|
297
|
-
workerData: { link },
|
|
298
|
-
transferList: [link.port]
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const results = await pool.run([
|
|
303
|
-
['render', 'page-1'],
|
|
304
|
-
['render', 'page-2']
|
|
305
|
-
]);
|
|
306
|
-
console.log(results.map((result) => result.text()));
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
```ts
|
|
310
|
-
import { workerData } from 'node:worker_threads';
|
|
311
|
-
import { serveTasks } from '@gmitch215/folio/tasks';
|
|
134
|
+
[Modules](docs/modules/README.md) helps choose between them, and
|
|
135
|
+
[Configuration](docs/configuration.md) lists every option. Subpaths from 1.1 that are not in this
|
|
136
|
+
table are no longer exported, and the
|
|
137
|
+
[CHANGELOG](https://github.com/gmitch215/folio/blob/master/CHANGELOG.md) lists where each of their
|
|
138
|
+
names moved. The generated API reference is published to GitHub Pages from `bun run docs:build`.
|
|
312
139
|
|
|
313
|
-
|
|
314
|
-
// run the task called `name` on `input` and return its output
|
|
315
|
-
return String(input);
|
|
316
|
-
});
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
A worker shares nothing with the owner. Each task runs against that worker's own state, so a task
|
|
320
|
-
that reads or writes state the serial program would have shared returns a different result than the
|
|
321
|
-
serial run. `audit: { run, every }` runs every nth task again in the joining thread and throws
|
|
322
|
-
`TaskConflictError` with the first differing byte. The audit costs one serial execution per checked
|
|
323
|
-
task and is meant for tests and canaries. `drain()` returns a record per joined task with its worker,
|
|
324
|
-
start and end time, thread CPU time and byte counts, and `peakConcurrency(records)` reports how many
|
|
325
|
-
tasks ran at the same time.
|
|
326
|
-
|
|
327
|
-
The pool does not discover independent work. Region discovery and ordered validation stay in the
|
|
328
|
-
core engine, and the task pool covers programs that can say which calls are independent.
|
|
329
|
-
|
|
330
|
-
`@gmitch215/folio/fold` covers one case where a single call is not independent but still splits
|
|
331
|
-
exactly. A CRC-32, an Adler-32 or an AES-CTR stream over one input is a recurrence with an exact
|
|
332
|
-
combine, so chunks run on separate tasks and join into the serial result. `chunkRanges(length,
|
|
333
|
-
count, align)` cuts the input, `foldChunks(pool, input, { task, initial, combine })` runs one task
|
|
334
|
-
per chunk and combines the results in order, and `crc32Combine`, `adler32Combine` and `ctrAdvance`
|
|
335
|
-
supply the algebra. AES chunks must be multiples of 16 bytes except the last. Chunks are copied into
|
|
336
|
-
their tasks, and 64 MiB of CRC-32 on eight workers ran 3.52x faster than serial with the result equal
|
|
337
|
-
to `zlib.crc32`. A recurrence with no known combine, such as one SHA-256 message, stays serial.
|
|
338
|
-
|
|
339
|
-
## 🍰 Slice Pool
|
|
340
|
-
|
|
341
|
-
`@gmitch215/folio/slices` runs an exported function over a range of calls on several threads, on one
|
|
342
|
-
shared memory, with no copy and no tracking. The caller declares that the calls are independent. A
|
|
343
|
-
`SlicePool` compiles the module once, marks its imported memory shared, grows the memory by one
|
|
344
|
-
private stack per worker when the module keeps a stack pointer global, and starts the workers.
|
|
345
|
-
`run(entry, count, args)` splits `[0, count)` into slices, and `args(from, to)` returns the arguments
|
|
346
|
-
of the call for a slice. The records go into `pool.memory` after `open`, because opening applies the
|
|
347
|
-
module's data segments, and the results are read from it afterwards.
|
|
348
|
-
|
|
349
|
-
```ts
|
|
350
|
-
import { SlicePool } from '@gmitch215/folio/slices';
|
|
351
|
-
|
|
352
|
-
const memory = new WebAssembly.Memory({ initial: 256, maximum: 4096, shared: true });
|
|
353
|
-
const pool = await SlicePool.open(bytes, { memory, workers: 8 });
|
|
354
|
-
write(pool.memory, records); // table, input bytes and an output area
|
|
355
|
-
|
|
356
|
-
const report = await pool.run('bulk', records.length, (from, to) => [
|
|
357
|
-
table + 16 * from,
|
|
358
|
-
to - from,
|
|
359
|
-
out + from * slot
|
|
360
|
-
]);
|
|
361
|
-
read(pool.memory, out, records.length * slot);
|
|
362
|
-
await pool.close();
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
The module must import its memory with a declared maximum that leaves room for the stacks, and keep
|
|
366
|
-
at most one mutable global, which is taken to be the stack pointer. A start function, a dropped
|
|
367
|
-
data segment or a second mutable global refuses the module. Arguments and results are i32 or i64
|
|
368
|
-
(`bigint`). Imports other than the memory come from `imports`, a module specifier whose default export
|
|
369
|
-
returns them, because functions do not cross threads.
|
|
370
|
-
|
|
371
|
-
Nothing here checks independence. A program that writes state the serial program would share
|
|
372
|
-
returns a different result. `run(..., { audit: true })` copies the memory before the run, runs the
|
|
373
|
-
same slices serially on the copy and compares every returned value and every byte below the
|
|
374
|
-
stacks, and throws `SliceConflictError` with the first difference. The audit costs a serial run and a
|
|
375
|
-
memory copy and is meant for tests and canaries. A route that copies each task's records into a
|
|
376
|
-
private context cannot win on a kernel whose speed is the copy's bandwidth; the slice pool has no
|
|
377
|
-
copy, and on the quiet rig xxHash, Adler-32 and LZ4 decompress over thousands of records ran 1.7x
|
|
378
|
-
to 4.9x faster than serial on eight workers (see the technical report).
|
|
379
|
-
|
|
380
|
-
## 🧮 Certified Stream Folds
|
|
381
|
-
|
|
382
|
-
`@gmitch215/folio/certify` decides whether an exported function `entry(state, ptr, len)` over a byte
|
|
383
|
-
stream is the left fold of one affine byte step, for every length of at least one byte, and
|
|
384
|
-
`@gmitch215/folio/certified` runs such a function on workers. `certifyStream(bytes, entry)` returns a
|
|
385
|
-
certificate or the reason it refused. The proof executes the function symbolically, so it covers the
|
|
386
|
-
unrolled main loop and tail that clang emits, tables the module carries or builds on its first call,
|
|
387
|
-
64-bit states and internal calls. The step is affine in the state over GF(2) (bit operations), over
|
|
388
|
-
Z/2^w (add and multiply) or over two 16-bit residues of one modulus (Adler-32 keeps its two sums this
|
|
389
|
-
way), and it may apply any pure function to the input bytes.
|
|
390
|
-
|
|
391
|
-
A certificate names the module digest. `verifyCertificate(bytes, certificate)` re-derives it from the
|
|
392
|
-
module, and `guardInput` checks that an input range stays inside memory and clear of the bytes the proof
|
|
393
|
-
read. With a certificate, `foldCertified` runs every chunk once from state zero on its own worker, reads
|
|
394
|
-
the input in place from shared memory and combines the end states with the recovered model. It does not
|
|
395
|
-
run a second pass, because the certificate replaces the validation that `foldAffine` needs when it only
|
|
396
|
-
has a sampled model.
|
|
397
|
-
|
|
398
|
-
```ts
|
|
399
|
-
import { Worker } from 'node:worker_threads';
|
|
400
|
-
import { certifyStream } from '@gmitch215/folio/certify';
|
|
401
|
-
import { foldCertified, installPrefill, shareCertified } from '@gmitch215/folio/certified';
|
|
402
|
-
import { TaskPool } from '@gmitch215/folio/tasks';
|
|
403
|
-
|
|
404
|
-
const certificate = certifyStream(bytes, 'crc32c');
|
|
405
|
-
if (certificate.kind === 'refusal') throw new Error(certificate.reason);
|
|
406
|
-
|
|
407
|
-
const pages = 256;
|
|
408
|
-
const subject = shareCertified(bytes, certificate, pages);
|
|
409
|
-
const memory = new WebAssembly.Memory({ initial: pages, maximum: pages, shared: true });
|
|
410
|
-
installPrefill(subject, memory);
|
|
411
|
-
const module = new WebAssembly.Module(subject.bytes);
|
|
412
|
-
|
|
413
|
-
const pool = new TaskPool(8);
|
|
414
|
-
for (let index = 0; index < 8; index++) {
|
|
415
|
-
const link = pool.link(index);
|
|
416
|
-
// worker.ts calls serveCertified(link, { module, memory, layout }) from workerData
|
|
417
|
-
new Worker(new URL('./worker.ts', import.meta.url), {
|
|
418
|
-
workerData: { link, module, memory, layout: certificate.layout },
|
|
419
|
-
transferList: [link.port]
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
const input = new Uint8Array(memory.buffer, 1 << 20, 64 * 1024 * 1024);
|
|
424
|
-
// fill the input here
|
|
425
|
-
const { state } = foldCertified(pool, input, memory, certificate);
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
A function that also rewrites its input in place, such as a stream cipher that xors a keystream into
|
|
429
|
-
the buffer, gets an `output` field when the proof shows that byte i becomes a fixed function of the
|
|
430
|
-
original byte and the fold state before it, and that nothing else is written. When the state does not
|
|
431
|
-
read the input bytes, `reconstructCertified` starts every chunk at its own state, which the model gives
|
|
432
|
-
without running the kernel, and each worker rewrites its own bytes once. A chunk that ends in a state
|
|
433
|
-
the model did not predict makes it throw, because the input is already rewritten. `foldCertified`
|
|
434
|
-
throws for a certificate with `output`: chunks that start from state zero would write the wrong bytes.
|
|
435
|
-
|
|
436
|
-
A refusal describes the checker and not the function: a function it cannot prove runs serially or through
|
|
437
|
-
`foldAffine` in exact mode. The checker refuses a branch on input data or on the state, a pointer or
|
|
438
|
-
length used as data, state kept in memory or globals, stores other than the in-place byte rewrite,
|
|
439
|
-
imports, a start function and passive data segments. A function that depends on the alignment of
|
|
440
|
-
its pointer or reads past its input is refused. `zeroLength` in the certificate says what a call over no bytes returns, and
|
|
441
|
-
`foldCertified` runs an empty input as the serial call.
|
|
442
|
-
|
|
443
|
-
## 🔏 Ownership Certificates
|
|
444
|
-
|
|
445
|
-
`@gmitch215/folio/ownership` checks whether a function that loops over records keeps its scratch
|
|
446
|
-
memory private to each record. Compiled drivers often write a fixed address (a scratch buffer, a
|
|
447
|
-
static table, a cursor) before they read it back, and records that run on several threads over one
|
|
448
|
-
memory collide there. `certifyOwnership(bytes, options)` takes an entry that is `bulk(table, count,
|
|
449
|
-
out, ...)` by default (`entry` and `convention` name another function and record layout), finds the
|
|
450
|
-
fixed-address windows the records write, and returns a certificate or a refusal. A certificate
|
|
451
|
-
covers six obligations: state isolation, read before write, aliasing through indirect pointers and
|
|
452
|
-
bulk operations, the final state the owner must rebuild, escaping addresses, and failure (a trap or
|
|
453
|
-
aborted iteration publishes nothing). The `prefix`, `config`, `recursion` and `allocator` options
|
|
454
|
-
widen the domain the checker handles, and each adds premises that the certificate lists.
|
|
455
|
-
|
|
456
|
-
A refusal carries a `reason` from the closed list `OWNERSHIP_REASONS`, the `obligation` it belongs
|
|
457
|
-
to, a `detail` and, where there is one, an `address`. The reasons are one per obligation
|
|
458
|
-
(`isolation`, `read-before-write`, `aliasing`, `final-state`, `escape`, `failure`), the pointer
|
|
459
|
-
rules of the allocator mode (`ptr-store`, `ptr-return`, `ptr-import`, `ptr-compare`, `ptr-control`,
|
|
460
|
-
`ptr-deref`, `allocator`), `prefix-store`, `prefix-cover`, `config-store`, and four about scope:
|
|
461
|
-
`no-window`, `unsupported`, `budget` and `invalid`. `budget` means the analysis hit its step limit
|
|
462
|
-
(4,000,000 by default) and says nothing about the program. Any refusal says what the checker could
|
|
463
|
-
not establish, and the function runs serially or on another route. On the 10 development drivers
|
|
464
|
-
that fail the plain slice pool, 6 certify.
|
|
465
|
-
|
|
466
|
-
`verifyOwnership(bytes, certificate)` re-derives the certificate from the module and compares
|
|
467
|
-
everything except the work counters. A certificate names the module digest and the checker version
|
|
468
|
-
(`OWNERSHIP_CHECKER`).
|
|
469
|
-
|
|
470
|
-
Two routes run a certified driver. `ownershipSlices` from `@gmitch215/folio/ownership-slices`
|
|
471
|
-
redirects every window access to a private copy per worker and runs the records in place on the
|
|
472
|
-
slice pool. A trap in any slice puts `writes` back and runs the calls serially in place, so the
|
|
473
|
-
serial run decides the memory and the trap. `ownershipSlices` throws `OwnershipSlicesError` with
|
|
474
|
-
code `wild-store` for a certificate that records stores no record owns. `run` throws it with code
|
|
475
|
-
`layout` when a record region overlaps a window, and with `config` when the memory differs from a
|
|
476
|
-
configuration the certificate assumed. `redirectOwnership` and `ownershipRoute` from
|
|
477
|
-
`@gmitch215/folio/ownership-redirect` make the same rewrite and hand it to the iteration pool,
|
|
478
|
-
which tracks every access and paid less on the module measured.
|
|
479
|
-
|
|
480
|
-
```ts
|
|
481
|
-
import { certifyOwnership, verifyOwnership } from '@gmitch215/folio/ownership';
|
|
482
|
-
import { ownershipSlices } from '@gmitch215/folio/ownership-slices';
|
|
483
|
-
|
|
484
|
-
const certificate = certifyOwnership(bytes, { entry: 'bulk' });
|
|
485
|
-
if (certificate.kind === 'refusal') {
|
|
486
|
-
throw new Error(`${certificate.reason} (${certificate.obligation}): ${certificate.detail}`);
|
|
487
|
-
}
|
|
488
|
-
if (!verifyOwnership(bytes, certificate)) throw new Error('the certificate does not re-derive');
|
|
489
|
-
|
|
490
|
-
const memory = new WebAssembly.Memory({ initial: 8, maximum: 40, shared: true });
|
|
491
|
-
const pool = await ownershipSlices(bytes, certificate, { memory, workers: 4 });
|
|
492
|
-
try {
|
|
493
|
-
// write the record table, the inputs and the output area into pool.memory here
|
|
494
|
-
const report = await pool.run(
|
|
495
|
-
count,
|
|
496
|
-
(from, to) => [table + 16 * from, to - from, out + 64 * from],
|
|
497
|
-
{
|
|
498
|
-
regions: [
|
|
499
|
-
[table, table + 16 * count],
|
|
500
|
-
[input, input + inputBytes],
|
|
501
|
-
[out, out + 64 * count]
|
|
502
|
-
],
|
|
503
|
-
writes: [[out, out + 64 * count]]
|
|
504
|
-
}
|
|
505
|
-
);
|
|
506
|
-
console.log(report.ownership?.replayed);
|
|
507
|
-
} finally {
|
|
508
|
-
await pool.close();
|
|
509
|
-
}
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
A certificate rests on premises that the checker does not prove, and a run that breaks one can
|
|
513
|
-
return a different result than the serial program:
|
|
514
|
-
|
|
515
|
-
- The record regions (table, output slots, inputs, auxiliary data, arena slices and stack slots)
|
|
516
|
-
do not overlap a window. `OwnershipSlices.run` checks the `regions` and `writes` the caller
|
|
517
|
-
passes, so they must be complete.
|
|
518
|
-
- Record-derived pointers stay inside their regions. The library does not check this one.
|
|
519
|
-
- The entry branches on its loop counters and the record count only to end or repeat its loop.
|
|
520
|
-
- A trap discards the private copies and the serial path decides what happens next.
|
|
521
|
-
- The start function and the host leave the window bytes the private copies start from.
|
|
522
|
-
- The stack pointer discipline and the stack residue are not proved.
|
|
523
|
-
|
|
524
|
-
The `allocator`, `prefix` and `config` modes add their own premises, which the certificate lists in
|
|
525
|
-
`allocator.assumptions`, `prefix.rules` and `config.rules`. The checker has produced false
|
|
526
|
-
certificates. A red team round found three classes of them that earlier mutation testing had not
|
|
527
|
-
found, and the fixes are part of this release. Red team round 3 found four more classes before the
|
|
528
|
-
checker was frozen, and those are closed too. On the frozen checker, the adversary families and two
|
|
529
|
-
generators of 20,000 modules each found no module whose certificate was wrong. The adversary
|
|
530
|
-
families accept the same number of modules as before the fixes, so they do not exercise the new
|
|
531
|
-
refusals, and the generators have blind spots. The premises above still apply.
|
|
532
|
-
|
|
533
|
-
## 🚦 Router
|
|
534
|
-
|
|
535
|
-
`@gmitch215/folio/router` picks one route for a call from the module bytes and a description of
|
|
536
|
-
the call, runs it and says why. A call is `{ kind: 'stream', entry, ptr, len }` for one function
|
|
537
|
-
`entry(state, ptr, len)` over a byte stream, or `{ kind: 'records', entry, count, args, regions,
|
|
538
|
-
writes }` for a loop of independent calls, where `args(from, to)` returns the arguments of a slice.
|
|
539
|
-
`Router.open(bytes, call, options)` decides and builds the memory and pools its route needs, and
|
|
540
|
-
`router.run()` executes the call. `decide(bytes, call, options)` returns the decision without
|
|
541
|
-
running anything. A parallel route over a records call needs a module that imports its memory,
|
|
542
|
-
which the router allocates shared.
|
|
543
|
-
|
|
544
|
-
The order is fixed. A stream takes the certified summary when `certifyStream` returns a
|
|
545
|
-
certificate. A loop of records takes the certified window when the ownership certificate exists,
|
|
546
|
-
records no wild stores and the regions clear its windows, then the explicit runner in
|
|
547
|
-
`options.explicit` if the caller supplied one, then tracked speculation, then serial. Tracked
|
|
548
|
-
speculation runs only after an ownership refusal for allocator state or a missing window, and only
|
|
549
|
-
when `assume` states that imports are deterministic (or absent) and that nothing reads the stack
|
|
550
|
-
zone afterwards. `mode` limits the routes: `router` is the whole chain, `serial` never leaves the
|
|
551
|
-
owner, `w1` is the summary only and `w2` the window only, and `independent` and `shared` try the
|
|
552
|
-
summary and then the window, with the module analyses made independently or shared. The last
|
|
553
|
-
four are the arms of the development ablation.
|
|
554
|
-
|
|
555
|
-
Certificates and refusals go into a `CertificateCache`, keyed by the module's SHA-256 and by the
|
|
556
|
-
backend, the checker versions, `ROUTER_VERSION` (`folio-router-2`) and the options that change a
|
|
557
|
-
certificate. A refused module costs a map lookup after the first call, and `serialize()` and
|
|
558
|
-
`load()` move the cache between processes. A route has a floor: the window route stays serial below
|
|
559
|
-
0.8 ms of remaining serial work and the summary route below 1 MiB, both in `routerConstants`, and
|
|
560
|
-
the tracked and explicit routes use the admission floor of the iteration route. The router runs the
|
|
561
|
-
first records of a call serially to estimate that time, and it stops dispatching after two losing
|
|
562
|
-
dispatches in a row. The constants were fitted on development data, so a result on the development
|
|
563
|
-
drivers describes the fit, and the figure on the frozen final corpus is in Measured Results.
|
|
564
|
-
|
|
565
|
-
```ts
|
|
566
|
-
import { Router } from '@gmitch215/folio/router';
|
|
567
|
-
|
|
568
|
-
const router = await Router.open(
|
|
569
|
-
bytes,
|
|
570
|
-
{
|
|
571
|
-
kind: 'records',
|
|
572
|
-
entry: 'bulk',
|
|
573
|
-
count,
|
|
574
|
-
args: (from, to) => [table + 16 * from, to - from, out + 64 * from],
|
|
575
|
-
regions: [
|
|
576
|
-
[table, table + 16 * count],
|
|
577
|
-
[input, input + inputBytes],
|
|
578
|
-
[out, out + 64 * count]
|
|
579
|
-
],
|
|
580
|
-
writes: [[out, out + 64 * count]]
|
|
581
|
-
},
|
|
582
|
-
{ mode: 'router', pages: 8, maxPages: 40, workers: 4 }
|
|
583
|
-
);
|
|
584
|
-
try {
|
|
585
|
-
console.log(router.decision.route, router.decision.reason, router.decision.detail);
|
|
586
|
-
for (const step of router.decision.considered) {
|
|
587
|
-
console.log(step.route, step.verdict, step.reason);
|
|
588
|
-
}
|
|
589
|
-
// write the record table, the inputs and the output area into router.memory here
|
|
590
|
-
const run = await router.run();
|
|
591
|
-
console.log(run.route, run.reason, run.wallMs);
|
|
592
|
-
} finally {
|
|
593
|
-
await router.close();
|
|
594
|
-
}
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
A refusal is a decision with `route: 'serial'` and a `reason` from the closed list
|
|
598
|
-
`ROUTER_REASONS`. The first four reasons are routes taken (`certified-summary`,
|
|
599
|
-
`certified-window`, `explicit-runner`, `tracked-eligible`) and the rest are refusals, such as
|
|
600
|
-
`allocator-state`, `shared-state`, `wild-store`, `layout-overlap`, `assumption-unasserted`,
|
|
601
|
-
`memory-not-imported` and `below-floor`. `decision.considered` lists each route in the order the
|
|
602
|
-
router looked at it, with a `verdict` of `taken`, `refused` or `skipped`, its reason and a `detail`
|
|
603
|
-
that quotes the certifier's refusal. `decision.cacheHit` and `certifyMs` say whether the analysis
|
|
604
|
-
was paid for on this call. The `route` that `run()` returns is the route that executed, which
|
|
605
|
-
differs from the decision when a floor sends the call to the owner (`below-floor`) or the loss rule
|
|
606
|
-
stops a dispatch (`dispatch-lost`).
|
|
607
|
-
|
|
608
|
-
## 🔄 Context Checkpoints
|
|
609
|
-
|
|
610
|
-
`@gmitch215/folio/context` resets a private Wasm instance between independent jobs.
|
|
611
|
-
`prepareContext(bytes)` from `@gmitch215/folio/compiler` adds exports for every memory, mutable
|
|
612
|
-
numeric global and table, and leaves function bodies and start sections as they are. An
|
|
613
|
-
`InstanceCheckpoint` copies that state once after initialization. `restore()` compares each 64 KiB
|
|
614
|
-
page with the copy, rewrites the pages that differ, and puts back globals and table references.
|
|
615
|
-
`restore('full')` copies every byte instead. Different inputs may dirty different pages, so the
|
|
616
|
-
checkpoint learns no page set from an earlier run.
|
|
617
|
-
|
|
618
|
-
```ts
|
|
619
|
-
import { prepareContext } from '@gmitch215/folio/compiler';
|
|
620
|
-
import { InstanceCheckpoint } from '@gmitch215/folio/context';
|
|
621
|
-
|
|
622
|
-
const plan = prepareContext(bytes);
|
|
623
|
-
const instance = new WebAssembly.Instance(new WebAssembly.Module(plan.bytes), imports);
|
|
624
|
-
initialize(instance);
|
|
625
|
-
const checkpoint = new InstanceCheckpoint(instance, plan);
|
|
626
|
-
|
|
627
|
-
for (const job of jobs) {
|
|
628
|
-
run(instance, job);
|
|
629
|
-
checkpoint.restore();
|
|
630
|
-
}
|
|
631
|
-
```
|
|
632
|
-
|
|
633
|
-
A module that drops a passive data or element segment, uses Wasm GC objects, or holds a reference or
|
|
634
|
-
`v128` global cannot be restored through exports. `prepareContext` then keeps the original bytes and
|
|
635
|
-
lists the causes in `plan.reasons`, and `InstanceCheckpoint` throws so the caller creates a fresh
|
|
636
|
-
instance for each job. Memory or table growth throws `ContextResetError` before anything is
|
|
637
|
-
written, and the caller instantiates a new context. Host resources and the objects behind
|
|
638
|
-
`externref` values stay with the caller. `restore()` reads every page, so its cost follows the memory
|
|
639
|
-
size and not the number of changed pages.
|
|
640
|
-
|
|
641
|
-
A job that writes its whole input region before it runs can skip that region.
|
|
642
|
-
`restore('changed', ranges)` takes `{ offset, length }` ranges (and a `memory` index when the plan has
|
|
643
|
-
more than one) that it neither compares nor copies back, and `skippedBytes` in the report counts them.
|
|
644
|
-
The caller must write every byte of a range before the program reads it, because those bytes keep the
|
|
645
|
-
previous job's contents. Everything outside the ranges is restored as before, and an invalid range
|
|
646
|
-
throws a `RangeError` before anything changes.
|
|
647
|
-
|
|
648
|
-
## 🧊 Baked Boot Images
|
|
649
|
-
|
|
650
|
-
`@gmitch215/folio/bake` moves a booted memory into the module. `captureImage(booted, fresh)` compares
|
|
651
|
-
a booted memory with a fresh instance of the same module and keeps the 64 KiB pages that differ.
|
|
652
|
-
`bakeModule(bytes, image)` returns the module with those pages as active data segments after its own,
|
|
653
|
-
so instantiating it starts from the booted memory. It uses binaryen, loaded on the first bake, and
|
|
654
|
-
writes memory 0.
|
|
655
|
-
|
|
656
|
-
```ts
|
|
657
|
-
import { bakeModule, captureImage, imagePages, moduleDigest } from '@gmitch215/folio/bake';
|
|
658
|
-
|
|
659
|
-
const fresh = new WebAssembly.Memory({ initial: 1024 });
|
|
660
|
-
const booted = new WebAssembly.Memory({ initial: 1024 });
|
|
661
|
-
// instantiate `bytes` on each memory, then run the boot sequence on `booted`
|
|
662
|
-
|
|
663
|
-
const image = captureImage(booted, fresh, { module: await moduleDigest(bytes) });
|
|
664
|
-
const baked = await bakeModule(bytes, image);
|
|
665
|
-
|
|
666
|
-
const memory = new WebAssembly.Memory({ initial: imagePages(image).memoryPages });
|
|
667
|
-
const { instance } = await WebAssembly.instantiate(baked, { env: { memory } });
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
The caller creates an imported memory with at least `memoryPages` pages. A defined memory that
|
|
671
|
-
starts smaller has its initial pages raised to the image size, and its maximum, shared and memory64
|
|
672
|
-
flags stay as they are. A page that boot zeroed but the module's own data had set is stored as
|
|
673
|
-
zeros, and pages that are zero in both are left out. Pass the global values and a pre-boot copy of
|
|
674
|
-
the same instance's table references to `captureImage` as `globals` and `table`; it records what boot
|
|
675
|
-
changed. `bakeModule` writes changed i32, i64, f32 and f64 globals into their initial values and
|
|
676
|
-
refuses changed table slots unless `allowTableChanges` is set. It throws `ImageMismatchError`, which
|
|
677
|
-
has a `code`, for a wrong module digest, a start function, no memory, an image over the memory
|
|
678
|
-
maximum and a global it cannot rewrite. Adjacent pages become one segment of at most `maxSegmentBytes` (64 MiB).
|
|
679
|
-
|
|
680
|
-
`applyImage(memory, image)` copies the pages into a fresh instance's memory without baking. It
|
|
681
|
-
cannot set a module's globals or table slots, so an image that records changed ones is refused with
|
|
682
|
-
code `global` or `table`; `{ memoryOnly: true }` copies the memory anyway and leaves the instance
|
|
683
|
-
with its fresh globals, which is not a booted instance. A module whose boot changes globals (the
|
|
684
|
-
PHP 8.5.12 build changes its stack bounds) belongs in `bakeModule`.
|
|
685
|
-
`captureImage` takes a `context` string beside the module digest, a digest of whatever else shapes
|
|
686
|
-
the heap (settings, shims, assets), and `applyImage(memory, image, { module, context })` refuses an
|
|
687
|
-
image whose module or context differs, or that carries none, with `ImageMismatchError` code `digest`
|
|
688
|
-
or `context` and before it writes a byte. `encodeImage` and `decodeImage` store an image beside the
|
|
689
|
-
module and reject truncated or unknown input with `ImageFormatError`. `checkBaked(baked, image)`
|
|
690
|
-
reads the data segments back and compares them with the image without instantiating.
|
|
691
|
-
`bakeModule` throws code `memories` for a module with more than one memory.
|
|
692
|
-
|
|
693
|
-
The image is the heap as it was, so anything the booted process held is in the baked module and
|
|
694
|
-
becomes public with it. State kept in JavaScript, such as handles and open descriptors, is not
|
|
695
|
-
captured. `findInImage(image, needles)` returns every offset where a needle's bytes occur in the
|
|
696
|
-
image pages, so a secret and its base64 and hex forms can be searched for before the module ships.
|
|
697
|
-
Freed memory is not zeroed, so a secret that was ever in the heap cannot be scrubbed out of an
|
|
698
|
-
image afterwards: bake a site whose key and salt are throwaway values, and give the replaying site
|
|
699
|
-
its own.
|
|
700
|
-
|
|
701
|
-
For a Drupal heap that means three replacements after the replay. The hash salt lives in the static
|
|
702
|
-
`Settings` object; the private key lives in the `State` cache collector, which serves it from memory
|
|
703
|
-
once read; and PHP's Mersenne Twister state is in the heap, so every replayed instance would draw
|
|
704
|
-
the same `mt_rand()` sequence. Values the bake computed from the old key and salt, such as the
|
|
705
|
-
permissions hash of the anonymous user, sit in the `cache.memory` bin. This snippet makes the
|
|
706
|
-
replayed instance use the replaying site's values, with `$salt` set to that site's hash salt:
|
|
707
|
-
|
|
708
|
-
```php
|
|
709
|
-
use Drupal\Core\Site\Settings;
|
|
710
|
-
|
|
711
|
-
(function (string $salt) {
|
|
712
|
-
$this->storage['hash_salt'] = $salt;
|
|
713
|
-
})->call(Settings::getInstance(), $salt);
|
|
714
|
-
|
|
715
|
-
(function () {
|
|
716
|
-
$this->reset();
|
|
717
|
-
$this->keysSetDuringRequest = [];
|
|
718
|
-
})->call(Drupal::state());
|
|
719
|
-
|
|
720
|
-
Drupal::service('cache.memory')->deleteAll();
|
|
721
|
-
mt_srand(unpack('V', random_bytes(4))[1]);
|
|
722
|
-
```
|
|
723
|
-
|
|
724
|
-
Run it before any other PHP in the replayed instance. The bake request's PHP session identifier also
|
|
725
|
-
stays in the heap and the library cannot renew it, so the host sets each request's own identifier
|
|
726
|
-
before it serves the request. A host that resets `State` at the start of
|
|
727
|
-
each request still needs the salt and the random seed, and needs the key step for code that runs
|
|
728
|
-
before the first request. The measured effect for a PHP interpreter is in the Baked Boot Images
|
|
729
|
-
section of the technical report.
|
|
730
|
-
|
|
731
|
-
## 🧱 Execution and Memory
|
|
732
|
-
|
|
733
|
-
Proved finite, nontrapping i32 kernels use runtime bounds and cross-region overlap checks, then
|
|
734
|
-
run native instructions against the shared allocation with no tracking or commit copy. A failed
|
|
735
|
-
guard falls back to tracked execution.
|
|
736
|
-
|
|
737
|
-
Tracked regions read a frozen shared base and keep private byte overlays. Once every reader stops,
|
|
738
|
-
Folio validates and commits in order. Conflicts replay against committed state, budgets discard
|
|
739
|
-
speculation, and ordered traps keep their preceding writes while later results are discarded.
|
|
740
|
-
|
|
741
|
-
The coordinator keeps admitted scalar control flow and live results. Inline numeric-memory spans
|
|
742
|
-
become regions when modified locals have no external live-outs and are assigned before reads on
|
|
743
|
-
every admitted path. Pure nonrecursive calls with unused results also qualify. Opaque functions,
|
|
744
|
-
recursion, host effects and state operations join preceding regions and run at their original
|
|
745
|
-
owner. Transactional memory covers i32, i64, f32 and f64 scalar operations plus `memory.copy` and
|
|
746
|
-
`memory.fill`, including unaligned access, overlap, NaN payloads, bounds and traps. Growth and
|
|
747
|
-
initialization stay at the coordinator. Unsupported instructions, reference and vector state,
|
|
748
|
-
memory64 and multiple memories keep native execution.
|
|
749
|
-
|
|
750
|
-
Shared source memory has zero-copy physical backing across the worker group. Ordinary source memory
|
|
751
|
-
keeps its original identity and buffer semantics, with an explicit shared snapshot per speculative
|
|
752
|
-
batch and ordered writeback, and the report counts the snapshot bytes. Regions travel in batches of
|
|
753
|
-
up to 16 per worker, and a singleton at a join runs locally.
|
|
754
|
-
|
|
755
|
-
Each isolate keeps its own stack, globals, table, JS heap and instance. Shared linear bytes do not
|
|
756
|
-
merge GC heaps or make arbitrary callbacks transferable. Give Folio exclusive access to its
|
|
757
|
-
memories and native exports until a run settles, and refresh views after shared growth. A failure
|
|
758
|
-
during direct native writes can leave partial memory, so the failed group closes and the
|
|
759
|
-
application restores a checkpoint before retrying. Instruction-defined traps keep their order and
|
|
760
|
-
writes. Native stack capacity and allocation failure can differ between isolates.
|
|
761
|
-
|
|
762
|
-
## 📖 API Reference
|
|
763
|
-
|
|
764
|
-
| Member | Contract |
|
|
765
|
-
| -------------------------------------- | ---------------------------------------------------------------------------- |
|
|
766
|
-
| `run(name, args?, options?)` | One entry, automatic region discovery when supported |
|
|
767
|
-
| `runAll([{ export, args }], options?)` | Ordered sequence of calls; the lower-level speculation primitive |
|
|
768
|
-
| `inspect(name)` | Automatic plan and native guard availability, with analysis diagnostics |
|
|
769
|
-
| `diagnostics` | Module-wide optimization refusals |
|
|
770
|
-
| `capabilities` | Active same-process sharing, automatic extraction and validation mode |
|
|
771
|
-
| `memory` | The unique accessible arena, including a coordinator-exposed hidden memory |
|
|
772
|
-
| `memories` | Named imported and exported memory wrappers |
|
|
773
|
-
| `exports` | Original native exports for trusted host integration |
|
|
774
|
-
| `close()` and async disposal | Join worker termination and outstanding JSPI calls; repeated close shares it |
|
|
775
|
-
|
|
776
|
-
A run returns `values`, `mode`, participating `workers`, `regions`, `replayed`, `fallbacks` and an
|
|
777
|
-
optional routing `reason`. Generalized execution also reports `extraction`, `memoryMode` and
|
|
778
|
-
`snapshotBytes`. Mode is `serial`, `speculative` or `native-shared`, and a serial run reports zero
|
|
779
|
-
participating workers. An analysis refusal is distinct from a runtime dependency, a failed guard
|
|
780
|
-
and a small-workload decision.
|
|
781
|
-
|
|
782
|
-
Run options:
|
|
783
|
-
|
|
784
|
-
- `parallel: 'auto' | 'off' | 'speculate'` chooses automatic routing, original execution or tracked
|
|
785
|
-
regions.
|
|
786
|
-
- `maximumWorkers` caps participating workers without recreating the group, which limits
|
|
787
|
-
contention or leaves CPU for other jobs.
|
|
788
|
-
|
|
789
|
-
Pool options are `workers` (up to four by default), `memory`, `imports`, `minimumParallelWork`
|
|
790
|
-
(100,000 estimated iterations for proved kernels), `minimumRegionWork` and `assumedTripCount` (both
|
|
791
|
-
apply when `open` prepares raw bytes), `fuel` (100,000,000), `maxTransactionBytes` (262,144),
|
|
792
|
-
`promising`, `profile` and `adaptiveRouting`. With `adaptiveRouting`, a call shape (entry, width,
|
|
793
|
-
memory size and numeric arguments) whose last two runs mostly replayed or fell back runs natively
|
|
794
|
-
for the next 16 calls and is then probed again. It is off by default. A one-worker pool uses its
|
|
795
|
-
native entry and creates no idle worker.
|
|
796
|
-
|
|
797
|
-
Profiling is opt-in. `report.profile` holds elapsed time, worker observations, validation, commit
|
|
798
|
-
and replay time, and tracked read and write bytes. On generalized batches `workerWallMs` and
|
|
799
|
-
`workerCpuMs` hold per-region observations. Measure process CPU once at the coordinator, because
|
|
800
|
-
summing overlapping process-wide counters double counts.
|
|
801
|
-
|
|
802
|
-
Subpaths added in 1.1 for certified and routed execution, with their runtime exports and the types
|
|
803
|
-
that go with them:
|
|
804
|
-
|
|
805
|
-
| Subpath | Exports | Contract |
|
|
806
|
-
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
807
|
-
| `affine` | `probeAffine`, `foldAffine`, `foldExact`, `serveAffine`, `affineSerial`, `advance`, `predictEnd`, `AFFINE_TASK`, `gfApply`, `gfMul`, `mask`, `mulberry` | Sampled affine model of a stream function and its chunked fold, with the GF(2) helpers the model uses; `exact` mode validates every boundary |
|
|
808
|
-
| `ownership` | `certifyOwnership`, `verifyOwnership`, `guardRecords`, `checkConfig`, `memoryAccesses`, `OWNERSHIP_REASONS`, `OWNERSHIP_CHECKER` | Window certificate or typed refusal, its re-derivation, and the layout and configuration checks a router runs |
|
|
809
|
-
| `ownership-redirect` | `redirectOwnership`, `ownershipRoute`, `OwnershipRedirectError` | Rewrites a certified module so each window access adds a per-worker delta |
|
|
810
|
-
| `ownership-slices` | `OwnershipSlices`, `ownershipSlices`, `OwnershipSlicesError` | The slice pool over a certified module, with serial replay after a trap |
|
|
811
|
-
| `router` | `Router`, `openRouter`, `decide`, `analyzeModule`, `CertificateCache`, `defaultBackend`, `routerConstants`, `ROUTER_VERSION`, `ROUTER_REASONS` | Route choice per call, certificate cache and the decision record |
|
|
812
|
-
|
|
813
|
-
The generated API reference is published to GitHub Pages from `bun run docs:build`.
|
|
814
|
-
|
|
815
|
-
## 🧪 Consumer Harness
|
|
816
|
-
|
|
817
|
-
`scripts/probe/consumer.ts` measures any Wasm module against a native instance of itself. A consumer
|
|
818
|
-
file exports the module bytes, a factory for fresh imports and a list of cases. Each case prepares
|
|
819
|
-
state on the raw exports and returns the calls to time. The harness opens a native arm and one pool
|
|
820
|
-
per worker count, alternates the arms inside every round, and compares the whole memory and every
|
|
821
|
-
return value before it records a sample. A mismatch stops the run.
|
|
822
|
-
|
|
823
|
-
```sh
|
|
824
|
-
node scripts/probe/consumer.ts scripts/probe/consumers/tinyimg.ts results/mine/tinyimg.jsonl 20 1,2,4,8
|
|
825
|
-
bun scripts/analyze/paired.ts mine tinyimg.jsonl
|
|
826
|
-
```
|
|
140
|
+
## ⚠️ Limits
|
|
827
141
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
the
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
fallbacks, mode and the reason it stayed serial. The closing row holds `inspect` coverage for each
|
|
835
|
-
entry that ran. The summary reports the paired speedup (native over Folio, within each round) and
|
|
836
|
-
the CPU ratio, so a run that finds nothing to split says so with its numbers. The consumers in
|
|
837
|
-
`scripts/probe/consumers/` cover tinyimg, a Linux machine core and a process ABI probe, a serial
|
|
838
|
-
recurrence, the compute kernel and a kernel whose trip count is too small to pay for dispatch.
|
|
839
|
-
`scripts/probe/php-workloads.ts` runs the same comparison on a PHP 8.5 build that serves Drupal.
|
|
840
|
-
|
|
841
|
-
`scripts/probe/php-contexts.ts` opens N private PHP instances, one per worker thread, and runs a
|
|
842
|
-
snippet or the uncached Drupal render in each. Every result carries timestamps from inside the
|
|
843
|
-
thread and thread CPU, so a run can show that two instances executed at the same time.
|
|
844
|
-
`scripts/probe/php-concurrent.ts` uses it for the four-arm comparison of independent requests
|
|
845
|
-
(native serial, native concurrent, Folio serial, Folio concurrent). Independent requests scale
|
|
846
|
-
with the number of instances whether or not Folio is involved; the library adds nothing to that
|
|
847
|
-
result and the numbers are in the technical report.
|
|
848
|
-
|
|
849
|
-
`scripts/probe/php-regen.ts` regenerates a set of Drupal pages with private contexts pulling from
|
|
850
|
-
one queue and aborts if any page differs from the serial render. On ten cores it reproduced 31 pages
|
|
851
|
-
7.65x faster than one context. It also runs under Bun, which the task pool supports.
|
|
852
|
-
|
|
853
|
-
## 📈 Measured Results
|
|
854
|
-
|
|
855
|
-
| Backend | Environment | Result |
|
|
856
|
-
| ---------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
857
|
-
| Node, shared allocation | Ryzen 9 9900X, eight pinned workers, 256 MiB arena | 7.52x median elapsed speedup on a normally inlined C entry, 4.87% extra CPU work, every byte exact |
|
|
858
|
-
| Node, compute kernel | eight workers, 207 byte-exact samples | 7.62x, with total CPU 1.037x of serial |
|
|
859
|
-
| Node, Drupal regeneration | Ryzen 9 9900X, ten private contexts, 31 pages, n=20 | 7.65x median over one context, 1.087x process CPU, every page equal to the serial render |
|
|
860
|
-
| Managed Workers | deployed Durable Object lanes | 39 of 39 rows exact over RPC, fetch, streams and WebSockets; 1.62x end to end at four lanes |
|
|
861
|
-
| Browser Run | deployed Chromium, eight workers on one 256 MiB allocation | 3.87x with four workers on explicit partitions |
|
|
862
|
-
| Browser automatic extraction | FREE account, no JSPI, one ordinary counted-loop call over 256 MiB | 3.45x at eight workers, all memory and returns exact; n=3 exploratory wall time |
|
|
863
|
-
| Baked boot image | PHP 8.5.12 Drupal host in a Durable Object, assets, n=4 per arm | first request 72.9% less cpuTime and 52.4% less wall; serve after a drop 43.9% less cpuTime |
|
|
864
|
-
| Independent corpus | 21 kernels from nine upstream projects, Ryzen 9 9900X and Apple M2 Pro | default admission finds no plan and dispatches no worker for any kernel; forcing admission makes all 11 kernels that receive regions slower than native |
|
|
865
|
-
| Explicit tasks on private contexts | the same 21 kernels, eight batched `TaskPool` workers | 18 of 21 reach 2x or more with a learned-page reset and 8 of 21 with the input-independent checkpoint reset; the eight-worker arm varies by up to 1.5x between runs |
|
|
866
|
-
| Iteration route, outside program | BLAKE3 1.8.7 unmodified, 32 x 4 MiB and 128 x 256 KiB, Ryzen 9 9900X and M2 Pro | default admission through `Folio.run`: 2.4x to 3.1x and 2.0x on the Ryzen machine, 3.2x to 3.5x and 2.8x to 2.9x on the M2 Pro (warm calls, equal digests); 1.00x before. SHA-256 with a helper per input 1.7x to 2.1x, LZ4 no gain |
|
|
867
|
-
| Baked Drupal lifecycle | Apple M2 Pro, 15 paired rounds, compile through first render | 830.5 ms to 444.7 ms elapsed (1.90x), process CPU 0.56 of native, 12 of 13 selected configurations reuse the image |
|
|
868
|
-
| Managed range lanes | deployed Durable Object lanes, 8 MiB arena, 65,536 rounds | 1.98x to 2.00x over serial with `fuel` raised to 1e9 and 0.2% of the snapshot bytes on the wire; 0.84x to 0.90x at the default fuel, where the owner finishes serially |
|
|
869
|
-
| Managed SQLite shards | deployed Durable Object lanes, 1,000,000 rows, 4 and 8 shards, declared merges | 2.0x to 9.7x over one object across five queries, 178 samples equal to the serial result |
|
|
870
|
-
| Record-level corpus | 30 bulk drivers, Ryzen 9 9900X, three sessions of five rounds | default admission wins on 7 drivers (SHA-256 2.01x, MD5 1.46x, SHA-1 1.55x, miniz CRC-32 1.52x, AES-CTR 1.21x, LZ4 compress 1.06x); explicit private contexts win on 26 (1.48x to 3.64x on 25); every output equal to the serial one |
|
|
871
|
-
| Exact chunked recurrences | one 64 MiB stream, eight task workers, Apple M2 Pro | CRC-32 4.25x, Adler-32 5.00x, AES-128-CTR 3.69x with shared input; CRC-32 3.52x with copied chunks; outputs equal to `zlib` and `node:crypto` |
|
|
872
|
-
| Certified stream folds | ten stream subjects, eight task workers, three sessions, Ryzen 9 9900X | 3.4x to 4.1x at 8 MiB and 4.7x to 6.8x at 64 MiB over the serial call (serial median over steady median, median of sessions), process CPU 1.02 to 1.10 of serial at 64 MiB, every result equal to the serial call |
|
|
873
|
-
| Ownership certificate, slice route | frozen final corpus, 47 drivers from 10 projects | window certificate on 1 of 47 drivers (`minimp3-mp3dec_init`), run on the window in 21 of 30 arm64 rounds and 0 of 30 x86_64 rounds; router geomean stays 0.90, gate missed (`router-ablation-final.ts`, rig and Mac) |
|
|
874
|
-
| Router | frozen final corpus, 47 drivers from 10 projects | geomean 0.899 (0.861 to 0.935) on the Ryzen 9 9900X rig and 0.900 (0.858 to 0.941) on the Apple M2 Pro, three sessions each, against 1.20; slowest of the five slowest 0.594 and 0.561 against 0.90; 17,484 rows, 0 wrong; not met |
|
|
875
|
-
| Unmodified external programs | aobench, 6pack with FastLZ and llama2.c at `-O2`, Ryzen 9 9900X, seven rounds | the automatic route stays serial on all three: 1.002 (0.999 to 1.007), 1.002 (0.996 to 1.004) and 1.001 (0.998 to 1.003) over serial Wasm; the 1.20 pass line is not met; 0 wrong outputs in 126 timed samples |
|
|
876
|
-
| Software translation for paging | PHP stock front page render, Ryzen 9 9900X, ten pairs per cell | tau 1.581 (1.537 to 1.617), translated render over native minus one, against a gate of at most 1: not met at default V8 tiering; the objective stays open |
|
|
877
|
-
|
|
878
|
-
A streaming workload stops improving near four workers, and `maximumWorkers` caps the pool per run.
|
|
879
|
-
Managed Workers cannot share physical memory across isolates, so that backend copies snapshots. The
|
|
880
|
-
[technical report](TECHNICAL_REPORT.md) lists every figure with its instrument, the raw samples
|
|
881
|
-
live in [results/](results), and the Cloudflare probes are described in
|
|
882
|
-
[experiments/](experiments/README.md).
|
|
142
|
+
Folio keeps the serial result and does not promise a speedup. The automatic routes found no gain on
|
|
143
|
+
independent library kernels and on three unmodified outside programs, and the explicit routes win
|
|
144
|
+
where the caller names the independent work. [Limits](docs/limits.md) lists what does not
|
|
145
|
+
parallelize, the gates that were not met and the platform limits, and the
|
|
146
|
+
[technical report](TECHNICAL_REPORT.md) holds the figures, the instruments and the raw samples under
|
|
147
|
+
[results](https://github.com/gmitch215/folio/tree/master/results).
|
|
883
148
|
|
|
884
149
|
## 🔧 Development
|
|
885
150
|
|
|
@@ -894,11 +159,13 @@ bun run example
|
|
|
894
159
|
```
|
|
895
160
|
|
|
896
161
|
Fixtures need `clang` and `wasm-ld` with the `wasm32` target. Tests need Node 26 for JSPI.
|
|
897
|
-
`bun run test:coverage` runs the unit and integration projects with coverage, and `bun run
|
|
898
|
-
|
|
899
|
-
`FREE_CLOUDFLARE_API_TOKEN` are set
|
|
900
|
-
`FOLIO_CLOUDFLARE_API_TOKEN`. Layout notes live in
|
|
901
|
-
[
|
|
162
|
+
`bun run test:coverage` runs the unit and integration projects with coverage, and `bun run test:e2e`
|
|
163
|
+
deploys the probes to a Cloudflare account when `FREE_CLOUDFLARE_ACCOUNT_ID` and
|
|
164
|
+
`FREE_CLOUDFLARE_API_TOKEN` are set. The experiments also accept `FOLIO_CLOUDFLARE_ACCOUNT_ID` and
|
|
165
|
+
`FOLIO_CLOUDFLARE_API_TOKEN`. Layout notes live in
|
|
166
|
+
[tests/](https://github.com/gmitch215/folio/blob/master/tests/README.md),
|
|
167
|
+
[scripts/](https://github.com/gmitch215/folio/blob/master/scripts/README.md) and
|
|
168
|
+
[experiments/](https://github.com/gmitch215/folio/blob/master/experiments/README.md).
|
|
902
169
|
|
|
903
170
|
## 🤝 Contributing
|
|
904
171
|
|
|
@@ -909,4 +176,5 @@ samples.
|
|
|
909
176
|
|
|
910
177
|
## 📄 License
|
|
911
178
|
|
|
912
|
-
MIT. See [LICENSE](LICENSE).
|
|
179
|
+
MIT. See [LICENSE](https://github.com/gmitch215/folio/blob/master/LICENSE). The documentation
|
|
180
|
+
favicons in `docs/` are the Fluent UI Emoji tram car from Microsoft, licensed under MIT.
|