perf(ext): convert ext/kv and ext/webgpu JS sources to lazy-loaded scripts#33818
Conversation
fibibot
left a comment
There was a problem hiding this comment.
LGTM. Same clean ESM-to-IIFE conversion pattern as #33817 (which I just approved), applied to ext/kv/01_db.ts and ext/webgpu/00_init.js. Substance walks correctly across all 8 files.
What I verified
ext/kv/01_db.ts: ESM import { core, primordials } from "ext:core/mod.js" + import { ... } from "ext:core/ops" → IIFE const { core, internals, primordials } = globalThis.__bootstrap + const { ... } = core.ops. Single import.meta.log call in the queue handler error path swapped to internals.log. Named exports replaced with IIFE return object: { AtomicOperation, Kv, KvListIterator, KvU64, openKv }. ✓
ext/webgpu/00_init.js: minimal conversion — file just creates a loadWebGPU lazy loader and exports it. IIFE wrapping preserves semantics. ✓
Consumer updates (4 files):
runtime/js/90_deno_ns.js:30, 35:import * as kvandimport { loadWebGPU }→core.loadExtScript()calls. ✓runtime/js/98_global_scope_shared.js:46,98_global_scope_window.js:25,98_global_scope_worker.js:23: all threeloadWebGPUnamed imports → destructured fromcore.loadExtScript(). ✓
CI - 1 cache-action flake on Windows, otherwise green
Current status: 71 success, 1 failure, 1 skipped, ~23 in-flight. The signal is strong:
- All release-mode tests pass across all 5 platforms: 15/15
test node_compatshards, 10/10test specsshards, 5/5test unit_nodeshards. ✓ - Lint passes on all 3 platforms (linux/macos/windows × x86_64). ✓
- Debug-mode tests that have completed:
test node_compatlinux-aarch64 + macos-aarch64 (all 3 shards each),test unit_nodelinux-aarch64,test unitlinux-aarch64 + macos-aarch64 — all pass.
The one failure is test node_compat (2/3) debug windows-x86_64, but the job only ran 51 seconds and the only [error] is Node Action run completed with exit code -1073740791 (Windows STATUS_STACK_BUFFER_OVERRUN, 0xC0000409) inside the actions/cache/restore step's GetCacheEntryDownloadURL call. The runner's cache action crashed before any test ran — not a test failure.
For an ESM-to-IIFE conversion of pure JS files with no platform-specific surface, the green release-mode signal across all 5 platforms + green debug-mode on linux-aarch64 + macos-aarch64 + lint clean is sufficient confidence. The remaining in-flight debug shards aren't going to surface anything platform-specific that's not visible already.
Smaller observation (non-blocking)
ext/webgpu/00_init.js's entire content is just const loadWebGPU = core.createLazyLoader("ext:deno_webgpu/01_webgpu.js"); + the export. After the IIFE wrap, this file is 9 lines for what's essentially a single lazy-loader factory. Could probably be inlined into the consumers (90_deno_ns.js, the three 98_global_scope_*.js files) at some point, but that's a separate refactor and not blocking this PR.
Resolve KV conflicts after main's lazy-loading refactor (#33778, #33818, #33966) and host-object deserialize fix (#34380): - ext/kv/lib.rs: switch `esm` to `lazy_loaded_esm`, drop generics, use `Box<dyn DynamicDbHandler>` (matching #33966). - runtime/js/90_deno_ns.js: load 01_db.ts via `createLazyLoader` (ESM) instead of `loadExtScript` (lazy script). - ext/kv/01_db.ts, impl/*.ts: convert relative imports to `ext:deno_kv/` specifiers (cannot-be-a-base scheme rejects relative URLs in lazy ESM). - impl/sqlite_backend.ts, impl/remote_backend.ts: load now-lazy modules (`ext:deno_crypto`, `ext:deno_fetch`, `ext:deno_web/03_abort_signal`) via `core.loadExtScript` instead of static imports. - impl/kv.ts: same for `06_streams.js`; add `deserializers: cloneableDeserializers` to KV value/queue payload deserialization (port of #34380).
…ripts (denoland#33818) ## Summary - Convert `ext/kv/01_db.ts` from ESM to IIFE-wrapped lazy-loaded script (`lazy_loaded_js`) - Convert `ext/webgpu/00_init.js` from ESM to IIFE-wrapped lazy-loaded script (`lazy_loaded_js`) - Update all consumers (`runtime/js/90_deno_ns.js`, `runtime/js/98_global_scope_shared.js`, `runtime/js/98_global_scope_window.js`, `runtime/js/98_global_scope_worker.js`) to use `core.loadExtScript()` instead of ESM imports - Replace `import.meta.log` call with `internals.log` in `01_db.ts` Follows the same pattern established in denoland#33778, denoland#33780, denoland#33784, denoland#33800, denoland#33801, and denoland#33817.
Summary
ext/kv/01_db.tsfrom ESM to IIFE-wrapped lazy-loaded script (lazy_loaded_js)ext/webgpu/00_init.jsfrom ESM to IIFE-wrapped lazy-loaded script (lazy_loaded_js)runtime/js/90_deno_ns.js,runtime/js/98_global_scope_shared.js,runtime/js/98_global_scope_window.js,runtime/js/98_global_scope_worker.js) to usecore.loadExtScript()instead of ESM importsimport.meta.logcall withinternals.login01_db.tsFollows the same pattern established in #33778, #33780, #33784, #33800, #33801, and #33817.
Test plan
cargo checkpasses