Skip to content

Encode hosted SQLite text directly into snapshot index replies - #2045

Merged
callumalpass merged 1 commit into
mainfrom
sprint-w11-server-do-perf
Nov 28, 2026
Merged

callumalpass merged 1 commit into
mainfrom
sprint-w11-server-do-perf

Conversation

@callumalpass

Copy link
Copy Markdown
Member

Refs #2017

The hosted snapshot builder reads each resource path twice and its Markdown body once. The SQLite adapter previously allocated a UTF-8 byte array for each of those text cells, then copied it into the binary reply. It now encodes into the reply buffer and allocates a temporary array only when a multibyte suffix needs more room. Request strings share a UTF-8 decoder across independent, synchronous decodes.

Local Durable Object SQLite benchmark

Each inventory reads resource paths, byte lengths and multilingual bodies in 256-row pages. The harness checks byte-for-byte equality of all baseline and candidate replies, warms each arm for four rounds, then collects 32 paired samples with alternating order. Times are milliseconds per complete inventory. CPU is Linux process time for workerd. Temporary arrays count calls to TextEncoder.encode in a separate, untimed inventory.

Resources Arm Inventories per sample Wall p50 (ms) Wall p95 (ms) CPU p50 (ms) CPU p95 (ms) Temporary text arrays
1 Base 3,000 0.119 0.252 0.103 0.133 3
1 PR 3,000 0.107 0.262 0.090 0.123 1
8 Base 1,200 0.236 0.424 0.217 0.242 24
8 PR 1,200 0.212 0.294 0.192 0.217 4
4,096 Base 5 85.937 185.449 68.000 72.000 12,288
4,096 PR 5 66.882 130.491 54.000 58.000 97

The 4,096-resource fixture used 21% less median workerd CPU. On one resource, CPU and median wall time fell, while wall p95 rose by 0.010 ms. These measurements cover the adapter on local workerd. Production snapshot latency and billing were outside the experiment.

Independent repeat on the rebased head

After local CI finished, the same harness on Linux x86-64 with Node 24.22.2 and workerd 1.20261014.1 returned the following per-inventory results. The baseline ran faster in this session as well. Comparing arms within each run, median CPU fell 18% in the repeat and 21% in the original large fixture. Both small controls improved on all timing metrics in the repeat.

Resources Arm Inventories per sample Wall p50 (ms) Wall p95 (ms) CPU p50 (ms) CPU p95 (ms) Temporary text arrays
1 Base 3,000 0.036 0.049 0.040 0.057 3
1 PR 3,000 0.033 0.043 0.033 0.047 1
8 Base 1,200 0.068 0.079 0.075 0.092 24
8 PR 1,200 0.060 0.072 0.058 0.075 4
4,096 Base 5 21.388 32.491 22.000 34.000 12,288
4,096 PR 5 18.165 24.093 18.000 26.000 97

Reproduction

Run from the PR checkout on Linux with Node 24. The baseline adapter below is byte-identical to the version used for the first measurement.

git show 3feb2752797dbe71df5605e0700f97df870e5cc1:runtime/deploy/hosted-worker/src/sql.ts > /tmp/base-resource-sql.ts
cd runtime/deploy/hosted-worker
npm ci
node bench/resource-text.mjs /tmp/base-resource-sql.ts

Verification

  • Hosted-worker typecheck and full suite with the built WASM fixture passed. All 514 tests ran. New cases cover multibyte text crossing a buffer boundary, the exact 4 MiB limit, a one-byte overflow, and independent decoding after malformed UTF-8.
  • The remote server suite passed 1,533 tests and skipped 997. The isolated daemon E2E passed registration, read, create, update and refusal after sign-out.
  • The rebased head passed pnpm ci:local with two Vitest workers and CI retry settings. An earlier run hit the 5 s shared-window UI test timeout. All 506 UI tests passed on the final run. The patch changes hosted-worker TypeScript, its test and benchmark, and a changelog fragment.

@callumalpass
callumalpass added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 4a180b8 Nov 28, 2026
38 checks passed
@callumalpass
callumalpass deleted the sprint-w11-server-do-perf branch November 28, 2026 14:10
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