Skip to content

feat(runtime): add wasm plugin system#6

Merged
matchai merged 62 commits intomainfrom
wasm-plugin-integration
Apr 3, 2026
Merged

feat(runtime): add wasm plugin system#6
matchai merged 62 commits intomainfrom
wasm-plugin-integration

Conversation

@matchai
Copy link
Copy Markdown
Member

@matchai matchai commented Apr 2, 2026

No description provided.

matchai added 30 commits April 2, 2026 00:00
Add compact() Lua global that filters nil arguments and joins
remaining segments with spaces, enabling one-liner configs:

  compact(green("node:", nodejs.version), ctx.pwd, "❯")

Style functions (green, bold, etc.) now propagate nil - if any
argument is nil, the function returns nil instead of erroring.
This lets compact() skip entire styled segments when their data
is unavailable.

Replace anstyle with owo-colors for ANSI rendering. Test
assertions now use paint() + style() instead of inspecting
the StyledContent tree structure directly.
Ignore STARSHIP_CONFIG when it points to a .toml file (starship v1
leftover). Auto-detect plugin dir by falling back to
target/wasm32-unknown-unknown/release when the default plugins dir
has no .wasm files.

Config chunks now run in a custom Lua environment that returns
nil-proxy tables for undefined globals (e.g. uninstalled plugins),
preventing 'attempt to index nil' crashes. Warns once per unknown
global name per daemon lifetime.

Filter STARSHIP_PROFILE tracing to starship crates by defaulting
RUST_LOG, suppressing cranelift/wasmtime debug noise.
matchai added 16 commits April 2, 2026 19:51
Add -vv to both the top-level codspeed build and the nested cargo
builds in the runtime build script. Also detach the nested cargo from
the parent jobserver to rule out deadlock.
eprintln timing around each phase of the build script so we can see
whether the wasm plugin builds are slow or deadlocked. Nested cargo
gets -vv for full compilation output.
eprintln is suppressed without -vv which cargo-codspeed doesn't
support. cargo::warning always prints.
The build.rs spawns nested cargo builds for wasm plugins which
deadlocks on the parent cargo's target directory lock (cargo#6412).

Use --target-dir to isolate the child builds and strip inherited
RUSTFLAGS/jobserver env vars to prevent contention.
Run walltime on codspeed-macro and memory on a regular ARM runner in
parallel via matrix. Each mode builds separately since the measurement
instrumentation is baked into the binary at compile time.
…end config

Benchmarks wasmtime module compilation (plugin_load), single wasm
round-trip (plugin_call_method), and full config eval with plugin
proxy resolution (config_with_plugins).
Each mode has its own build->run chain so they don't block
each other.
Plugin benchmarks need the .wasm files at runtime. Upload them
alongside codspeed artifacts and download to repo root to preserve
the target/ directory structure.
WASM_PLUGIN_DIR is a compile-time path that doesn't exist on the
run runner. Fall back to cwd-relative target/ path when the
compiled-in path is missing.
build.rs outputs plugins to target/wasm-plugins/ but the upload
step and runtime fallback both referenced target/wasm32-unknown-unknown/.
Fixed all three locations: upload, wasm_path() fallback, and
bench wasm_bytes() helper.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 3, 2026

Merging this PR will improve performance by ×5.7

⚡ 2 improved benchmarks
✅ 3 untouched benchmarks
🆕 15 new benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 WallTime config_with_plugins N/A 715.3 µs N/A
🆕 WallTime cached_config[Compact] N/A 18.8 µs N/A
WallTime cached_config[With Modules] 48.7 µs 12.6 µs ×3.9
🆕 WallTime plugin_call_method N/A 18.6 µs N/A
WallTime cached_config[Minimal] 47.5 µs 8.3 µs ×5.7
🆕 WallTime plugin_load N/A 31.6 ms N/A
🆕 WallTime cold_start[Compact] N/A 392.2 µs N/A
🆕 Memory cached_config[With Modules] N/A 32.1 KB N/A
🆕 Memory cold_start[With Modules] N/A 415.8 KB N/A
🆕 Memory plugin_call_method N/A 293 B N/A
🆕 Memory cold_start[Minimal] N/A 399.7 KB N/A
🆕 Memory config_with_plugins N/A 439.1 KB N/A
🆕 Memory cached_config[Compact] N/A 32.6 KB N/A
🆕 Memory cold_start[Compact] N/A 416.2 KB N/A
🆕 Memory cached_config[Minimal] N/A 16.1 KB N/A
🆕 Memory socket_render[Minimal] N/A 25.4 KB N/A
🆕 Memory plugin_load N/A 8.1 MB N/A

Comparing wasm-plugin-integration (427b843) with main (9d9a5c5)

Open in CodSpeed

matchai added 11 commits April 2, 2026 21:45
The codspeed-macro runner ships Cargo 1.81 which doesn't support
edition 2024. Install current stable toolchain so cargo metadata
can parse the workspace.
codspeed-macro runner has older GLIBC than ubuntu-24.04. Building
on 22.04 produces a binary compatible with both runners.
Consistent runner across build and run jobs avoids GLIBC mismatch
with codspeed-macro and cache incompatibility between 22.04/24.04.
Use runtime env var with absolute workspace path instead of
current_dir() fallback, which is unreliable when CodSpeed
executes the binary.
Replace runtime file loading in tests/benchmarks with compile-time
embedded wasm bytes. Eliminates WASM_PLUGIN_DIR runtime env var,
wasm_path() fallback chain, and wasm-plugins artifact uploads.

CI workflow simplified: only target/codspeed is uploaded/downloaded.
Plugin bytes are baked into the binary by the runtime crate's
build.rs, which is the only crate that needs WASM_PLUGIN_DIR.
Replace the recursive StyledContent enum (Text | Styled { style, children })
with a flat StyledContent(Vec<Span>) where each Span carries fully resolved
styling. Styles are now merged at Lua construction time via Style::merge,
eliminating tree recursion and intermediate String allocations at render time.

Display impl streams directly to the formatter using owo_colors
fmt_prefix/fmt_suffix -- zero buffering, zero recursion.

Remove render_prompt wrapper, inline .to_string() / Display at call sites.
@matchai matchai merged commit 9fae52c into main Apr 3, 2026
7 checks passed
@matchai matchai deleted the wasm-plugin-integration branch April 3, 2026 08:20
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