Skip to content

perf(onlion): stop paying for SQLite in requests that never touch it - #137

Merged
wefio merged 2 commits into
mainfrom
perf/defer-wasm-load
Oct 30, 2026
Merged

wefio merged 2 commits into
mainfrom
perf/defer-wasm-load

Conversation

@wefio

@wefio wefio commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Doc owner: docs/decisions/implemented/2026-10-30-defer-wasm-load.{md,zh-CN.md,terms.yaml} (added in this PR).

Measured baseline on live: twelve sequential /health calls at 3.6-6.5 s each — every one a cold start (fresh isolate per request), every one paying for SQLite it does not use:

  • /health called sqliteReady() just to report a version string;
  • the EdgeOne build inlined wasm as base64 and built new WebAssembly.Module(...) at module scope, so decode + compile happened before the handler ran (the plugin comment said "lazily"; the emitted code was eager).

Now: a compiledWasm() factory compiles on first use; /health never loads SQLite; the request line reports sqlite_loaded so the claim is falsifiable.

Not verified

Not deployed; the 3.6-6.5 s figure is the before-state, and the after-state is unmeasured until this ships. The wrangler/Miniflare path (workerd precompiled module) is covered by the existing suite but not re-measured for speed.

wefio added 2 commits October 30, 2026 18:53
Measured before this change: twelve sequential /health calls on the live
endpoint took 3.6-6.5 s each. Every one of them is a cold start - this platform
starts a fresh isolate per request - and every one paid for SQLite it does not
use:

- /health called sqliteReady() before answering, purely to report a version
  string;
- the EdgeOne build inlined the wasm as base64 and built the WebAssembly.Module
  **at module scope**, so the decode and the compile happened before any handler
  ran (the plugin's comment claimed lazy; the emitted code was eager).

Now:
- the build emits a factory (`compiledWasm()`) that decodes and compiles on
  first use; worker.mjs accepts either that factory or workerd's precompiled
  module, so the wrangler path is unchanged;
- /health no longer loads SQLite, and says so instead of reporting a version it
  did not load;
- the always-on request line carries `sqlite_loaded`, so "the deferred load
  works" is a measurement rather than a claim - false means the request finished
  without decoding or compiling wasm at all.

37 PASS locally, including `sqlite_loaded: false` on metadata routes.
@wefio
wefio merged commit f86d384 into main Oct 30, 2026
8 checks passed
@wefio
wefio deleted the perf/defer-wasm-load branch October 30, 2026 10:58
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