Repository navigation
Speed up browser cold open by promoting staged records and batching index reads - #2043
Merged
Merged
Conversation
callumalpass
enabled auto-merge
November 28, 2026 13:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1648
Promote the staged SQLite record table inside the existing snapshot-swap transaction. SQLite keeps the table's document pages in place. The transaction restores the canonical path and bucket indexes, recreates empty staging, swaps the remaining tables and publishes the head together. The rollback test aborts a later link insert after promotion and then retries the full swap.
Raw backfill now reads a bounded group of IDs with one ordered left join. Each missing or over-limit source keeps its slot, and a row above its share of the page still gets a bounded singleton read. The app SQLite bridge borrows batch parameters. Core borrows parsed frontmatter and skips runs of plain text while scanning for tags, preserving the existing admission charges.
GCP Chrome with real OPFS
Baseline
611f93f5e3438911c4bdd2561885484301546590, candidate source5c481c30ff05b4b3a79425d8d3c395f8ad16a49b, publication pin9b94bb14254824d9962fb32e3b25f17b788a83fd. Chrome 155.0.8059.84, Linux, ext4-backed fresh persistent profile and SQLite-WASM SAH-pool per sample. Seven pairs per fixture, alternating A/B then B/A. Timings exclude setup, digesting and teardown. Each combined value is the sum of the two phases from the same run. Nearest-rank p95 is the slowest of seven. The query is the first SDK top-50 task page after replay, filtering on priority and ordering descending.10,000 notes, 10,080 records at head
100-note control, 180 records at head
The 10k combined median fell 20.0% and p95 fell 11.6%. The first browser query was 0.18 ms slower at the median. The 100-note combined median fell 3.14 ms while its p95 rose 2.90 ms.
A supplemental native 10k top-50 benchmark measured median query time of 606.64 → 582.14 µs, index selection of 223.18 → 215.81 µs and hydration of 178.59 → 176.83 µs. Each revision ran separately on the shared builder using
cd runtime && rcargo test --release -p mdbn-bench --test indexed_query indexed_top50_over_10k_timing -- --ignored --nocapture.Where the 10k open spends time
The separate profile run measured 5,875 ms before and 2,973 ms after for install. SQLite accounted for 4,755 → 1,985 ms, including 1,504 → 841 ms in OPFS writes and 2,115 → 320 ms in flushes. Stepping explicit commits took 2,477 → 1,293 ms. Copying staged records into confirmed storage took 398 ms before promotion. These measurements overlap. The alternating unprofiled pairs above measure wall-clock performance.
The 9,450 statements removed from replay are record reads (11,589 → 2,139). The remaining 65,930 include 10,080 raw fact inserts, 10,080 raw record inserts, 10,030 raw atom inserts, 4,410 field inserts, and 3,090 link inserts. On the candidate, SQLite stepping took 706 ms for the raw atom inserts, 635 ms for explicit commits, 605 ms for FTS inserts and 333 ms for the field index. An earlier candidate batched raw fact writes and cut replay to 48,957 statements, but its median replay was 82 ms slower than its paired baseline. That version was discarded.
Equivalence and validation
The digest run hashes typed, length-delimited values in primary-key order for record blobs, resources, links, unique and field indexes, query projections and the FTS shadow tables. The query digest covers the ordered 50 IDs, paths and revisions. Each digest matched across both binaries.
a4e947b1d1fc78f12013192b916585c8b9a849059139d33247e6591a95fd246abc2a028fa902b1aaf9ba149287882a46c96c540e9d2718c69b2c68f35e8d3a9c5af203ccfeae071c9ff1c4447d2f2febe8fb51eaca5bcb5a1a8530bd6430f045ac7ff338e5e4e9ccc2dddacb81cc773e1f2db412097cf8124eac8e91d689b7c9256ffec33590e0c615e555628a02ba36f7912c4edb9e82cab5398e3f6eb997d336bf33863d46477401458b745210d2770babc28ab18ffe0e85c1699eae4d1dbabc0ece9ff1f987117ecb040b074278851284a3d828573a3f76c894683962afc7and the Stage 4 local build5ef991a30f99fdcca221058ff260bd932156559d42d693e5b5d504400ce15a2f. Two local builds reproduced that candidate. The publication build uses the same Rust source and remaps source paths, including Cargo registry paths. Its SHA-256 isd5452814d656c9611d0be04a934278d88ca8c83d3e823353f9842811a63a4795, raw 4,141,990 bytes (+1,534 over Stage 3), gzip 1,666,594 bytes, Brotli 1,219,256 bytes. The browser timing table applies to the benchmark builds. Runtime CI artifactrcargorebuild matched the GitHub artifact byte-for-byte. On the corrected pin,check-runtime-pinandpack-allpassed. Cold consumer checks passed and the extracted WASM in each of the production, staging and lab archives matched the published pin.pnpm ci:localpassed. The six-cratercargosuite passed 2,661 tests (7 ignored), and all three store-format upgrade tests passed. Native and WASM clippy, the runtime architecture check, 17 native/WASM golden replay fixtures, the app-WASM SQLite smoke tests, and the daemon end-to-end request path passed.node scripts/sdk-publication.mjs check-runtime-pinpassed.gcp/w16-opfs4destroyed and absence verified withdesk ls.Reproduce the publication build and archive verification
From the repository root on a Linux build host with the pinned Rust toolchain, Node 24 and npm installed, run the same app build and path normalization as the publication workflow.
Reproduce the benchmark
Use the pinned Stage 3 binary as
BEFORE. Its SHA-256 is listed above. In the Stage 4 source checkout, build the benchmark candidate asAFTERwith the pinned Binaryen and Rust toolchain:cd runtime npm ci --prefix tools/wasm rcargo --pull wasm32-unknown-unknown/wasm-release/mdbn_wasm.wasm build --locked -p mdbn-wasm --lib --target wasm32-unknown-unknown --profile wasm-release --features app-runtime mkdir -p target/wasm tools/wasm/node_modules/.bin/wasm-opt -Oz --converge --enable-bulk-memory --enable-bulk-memory-opt --enable-sign-ext --enable-mutable-globals --enable-nontrapping-float-to-int --enable-reference-types --enable-multivalue --strip-debug --strip-producers target/wasm32-unknown-unknown/wasm-release/mdbn_wasm.wasm -o target/wasm/app-runtime.wasmFrom the root of the baseline checkout generate the signed fixtures. Use the baseline SDK harness and SQLite package for both variants.
For the query and its digest, apply this measurement-only probe to the disposable copy of the baseline worker. The probe runs after both cold-open timers stop.
Run from the baseline checkout’s
runtimedirectory on the same disk-backed Chrome host using Bash. SetBEFOREandAFTERto the absolute paths of the two optimized modules.