Skip to content

perf(ext): convert ext/kv and ext/webgpu JS sources to lazy-loaded scripts#33818

Merged
bartlomieju merged 1 commit into
mainfrom
perf/lazy-load-kv-webgpu
May 4, 2026
Merged

perf(ext): convert ext/kv and ext/webgpu JS sources to lazy-loaded scripts#33818
bartlomieju merged 1 commit into
mainfrom
perf/lazy-load-kv-webgpu

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

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 #33778, #33780, #33784, #33800, #33801, and #33817.

Test plan

  • cargo check passes
  • CI passes (existing spec/unit tests cover ext/kv and ext/webgpu functionality)

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kv and import { 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 three loadWebGPU named imports → destructured from core.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_compat shards, 10/10 test specs shards, 5/5 test unit_node shards. ✓
  • Lint passes on all 3 platforms (linux/macos/windows × x86_64). ✓
  • Debug-mode tests that have completed: test node_compat linux-aarch64 + macos-aarch64 (all 3 shards each), test unit_node linux-aarch64, test unit linux-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.

@bartlomieju
bartlomieju merged commit a317222 into main May 4, 2026
267 of 270 checks passed
@bartlomieju
bartlomieju deleted the perf/lazy-load-kv-webgpu branch May 4, 2026 10:23
bartlomieju added a commit that referenced this pull request May 27, 2026
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).
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…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.
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.

2 participants