Skip to content

feat(transpile): load components at runtime with jit and binding plans - #2599

Open
vados-cosmonic wants to merge 16 commits into
bytecodealliance:mainfrom
vados-cosmonic:feat/transpile-jit
Open

vados-cosmonic wants to merge 16 commits into
bytecodealliance:mainfrom
vados-cosmonic:feat/transpile-jit

Conversation

@vados-cosmonic

@vados-cosmonic vados-cosmonic commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on #2600: the first five commits are that PR's, and this one starts at refactor(transpile): build bindgen options in a browser-safe module.

Adds @bytecodealliance/jco-transpile/jit, which loads a component at runtime ("just in time") instead of transpiling it in a build step:

import { loadComponent } from '@bytecodealliance/jco-transpile/jit';

const component = await loadComponent(fetch('/plugin.wasm'));
const instance = await component.instantiate(imports); // repeatable
  • Streaming compile. streamComponent walks the component's sections as bytes arrive (including nested components) and pipes each core module into WebAssembly.compileStreaming as soon as its section starts, so compiling overlaps the download.
  • Same bindings as jco transpile. Bindings come from the existing bindgen, lazily imported, with --instantiation async semantics. They import @bytecodealliance/jco-cm-runtime rather than embedding it, and get the streamed modules through getCoreModule, because guest modules are emitted byte-identical to their range of the input.
  • Cacheable. Bindings are plain data keyed by the component's digest and options, so a component loaded again skips the bindgen entirely.
  • Binding plans. With bindingPlan: true, the streaming decoder from feat(bindgen): add experimental component binding plans #2600 reads the same chunks as the download. A component within plan version 1 runs from its plan and the modules compiled while streaming, without importing the bindgen, and keeps the export names generated bindings use. Any other component falls back to generated bindings.
  • Small entry point. /jit is ~3.9 KB gzipped before the decoder or the bindgen is needed.

To share option handling with transpile, the mapping of transpile options to bindgen options moves into a module without Node.js dependencies.

Not in this PR yet

  • Browser tests for /jit, and the jco-transpile version in the bindings cache key.

@vados-cosmonic vados-cosmonic changed the title feat(transpile): load components at runtime with a jit export feat(transpile): load components at runtime with jit and binding plans Dec 2, 2026
The mapping of transpile options to bindgen options moves to a module without Node.js
dependencies, so that bindings can be generated where Node.js built-ins are not available.
`@bytecodealliance/jco-transpile/jit` reads a component as it downloads, compiling each core
module it embeds as soon as its bytes arrive, then generates bindings with the bindgen of
`jco transpile`. The bindings import the shared Component Model runtime, reuse the modules
compiled during the download, and can be cached so that a component loaded again skips the
bindgen.
With `bindingPlan`, the streaming decoder reads the same chunks as the download. A component
that a version 1 plan describes is instantiated from that plan and the modules compiled while
streaming, without importing the bindgen. Any other component gets generated bindings.
@vados-cosmonic
vados-cosmonic marked this pull request as ready for review December 2, 2026 14:09

This branch has not been deployed

No deployments
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