Skip to content

Reuse parsed link metadata and batch cold-open query index writes - #2036

Merged
callumalpass merged 3 commits into
mainfrom
sprint-w12-wasm-stage3-10k-open
Nov 28, 2026
Merged

callumalpass merged 3 commits into
mainfrom
sprint-w12-wasm-stage3-10k-open

Conversation

@callumalpass

@callumalpass callumalpass commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Refs #1648

A record's parsed frontmatter, membership, path-derived values and body now feed both sides of the link index during metadata derivation. SQLite writes record paths, modification-time sort keys and type memberships in bounded multi-row inserts using the existing 100-bind helper. The same transaction still publishes index coverage. The cold-open regression counts the rows SQLite actually changed and checks that an insert can cover multiple rows.

Chrome OPFS cold open

Seven fresh disk-backed profiles per build and collection size. Each pair reverses the preceding pair's order. Google Chrome 155.0.8059.84 ran on an isolated GCP desk with ext4, the pinned SQLite WASM, the SDK Worker bridge and the real OPFS SAH pool. The synthetic transport serves the same sealed records to both builds. Fixture generation, browser startup and integrity comparisons are outside the timings.

Task notes Phase Baseline median ms Candidate median ms Baseline p95 ms Candidate p95 ms
10,000 Snapshot install 4,553.29 4,467.21 4,823.73 4,584.15
10,000 Tail replay and query indexing 5,924.41 5,697.62 6,219.06 6,003.60
10,000 Install + replay 10,427.66 10,168.28 10,866.47 10,581.15
100 Snapshot install 85.97 89.53 90.99 99.31
100 Tail replay and query indexing 171.75 166.70 175.30 186.13
100 Install + replay 257.38 257.61 264.73 275.67

Totals use each run's elapsed sum. With seven samples, nearest-rank p95 is the slowest run. Both fixtures add 50 project notes, then 30 creates and two catalog changes after the snapshot. The 10k median total fell 259.38 ms (2.49%). The small median total rose 0.23 ms and its p95 rose 10.94 ms.

Where the time goes

10k phase and build Statements Host calls Request bytes SQLite ms OPFS read/write/flush ms within SQLite Host bridge outside SQLite ms Outside host and fixture ms
Install, baseline 1,956 536 25,766,695 3,483.1 2,821.0 89.0 977.4
Install, candidate 1,956 536 25,766,695 3,504.9 2,848.3 87.8 886.1
Replay, baseline 104,683 5,027 46,475,444 3,928.9 929.1 421.0 1,550.4
Replay, candidate 75,380 5,027 45,092,565 3,831.8 925.0 416.8 1,441.9

Columns report independent medians. The last column includes runtime verification, decompression, metadata derivation and projection as well as host driving. OPFS time overlaps SQLite time.

In a separate instrumented baseline run, SQLite spent 1,292 ms stepping explicit commits during install, 355 ms inserting staged records and 353 ms copying records to the confirmed table. During replay the largest step groups were raw frontmatter atom inserts (734 ms), explicit commits (610 ms), trigram body index inserts (602 ms), sort-field inserts (335 ms), and record reads (293 ms). Statement-step times exclude binding and row extraction. The change removes 29,303 replay statements with the same host-call count and the same verified records.

Correctness and build

The verification mode compares SHA-256 over the ordered typed values of all record, resource, link, uniqueness and field rows, the query tables, and the contentless FTS shadow tables. It checks both phases in separate runs. All four comparisons matched, and both raw and field indexes reported ready at the final head.

Fixture After install After replay
10k a4e947b1d1fc78f12013192b916585c8b9a849059139d33247e6591a95fd246a bc2a028fa902b1aaf9ba149287882a46c96c540e9d2718c69b2c68f35e8d3a9c
100 ac7ff338e5e4e9ccc2dddacb81cc773e1f2db412097cf8124eac8e91d689b7c9 256ffec33590e0c615e555628a02ba36f7912c4edb9e82cab5398e3f6eb997d3

Regenerating the 10k fixture from the candidate reproduced the benchmark input byte for byte (SHA-256 62fb23a7f8ba6b8d26a53d3ae812581469b8356b5e73fb20673be3efe8bf2b83). A second remapped compile and wasm-opt run reproduced the candidate app binary byte for byte.

The remapped baseline rebuilt from b723b6c4e matched the existing SDK pin. Candidate app WASM SHA-256 is bc0ece9ff1f987117ecb040b074278851284a3d828573a3f76c894683962afc7. Report-only raw / gzip / Brotli sizes changed from 4,135,951 / 1,663,813 / 1,218,197 to 4,140,456 / 1,665,683 / 1,218,694 bytes. The SDK asset pin and size bound were generated and verified together.

Native core, replica, file store, native platform and benchmark tests passed (2,531). App-feature tests and wasm32 clippy passed. Native, WASM and all 17 determinism goldens matched. The real SQLite app-WASM smoke, SDK tests (3,093 Vitest and 65 Node tests), and daemon E2E passed. The first full SDK run encountered a Unix socket path-length error and a compiler test timeout. A short checkout passed the entire suite. The repository-selected pnpm ci:local gates passed.

Reproduction

Build optimized app modules in two clean checkouts at the baseline and this branch. On a Linux CI runner with the repo-pinned toolchain, run the following in each checkout, preserving the two output paths.

cd runtime
npm ci --prefix tools/wasm
export RUSTFLAGS="--remap-path-prefix=$(git rev-parse --show-toplevel)=/source --remap-path-prefix=${CARGO_HOME:-$HOME/.cargo}=/cargo"
cargo xtask wasm-app
sha256sum target/wasm/app-runtime.wasm

From the candidate repo root, with BASE and CANDIDATE set to the absolute module paths and Chrome installed:

pnpm install --frozen-lockfile
cd runtime
npm ci --prefix packages/sdk
rcargo --pull tmp/cold-open.cbor test --locked --release -p mdbn-bench --test catalog_reindex seven_cold_opens_at_10k -- --ignored --nocapture
rcargo --pull tmp/cold-open-small.cbor test --locked --release -p mdbn-bench --test catalog_reindex seven_cold_opens_at_100 -- --ignored --nocapture
export TMPDIR="$PWD/target/browser-profiles" COLD_OPEN_CHROMIUM=/usr/bin/google-chrome
mkdir -p "$TMPDIR"
bench=packages/sdk/scripts/cold-open-bench.mjs
node "$bench" --verify "$BASE" "$CANDIDATE"
node "$bench" --small --verify "$BASE" "$CANDIDATE"
node "$bench" "$BASE" "$CANDIDATE"
node "$bench" --small "$BASE" "$CANDIDATE"
node "$bench" --profile "$BASE" "$CANDIDATE"

@callumalpass
callumalpass added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 611f93f Nov 28, 2026
45 checks passed
@callumalpass
callumalpass deleted the sprint-w12-wasm-stage3-10k-open branch November 28, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant