Skip to content

Optimize SpiderMonkey fetch dispatch#8

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/jit
Open

Optimize SpiderMonkey fetch dispatch#8
Copilot wants to merge 8 commits into
mainfrom
copilot/jit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

SpiderMonkey benchmarks were near parity with Boa because each request re-entered JavaScript through generated script evaluation. This changes the hot path to invoke the registered fetch dispatcher directly.

  • SpiderMonkey dispatch

    • Replace per-request evaluate_script("__helios_call_fetch(...)") with JS_CallFunctionName.
    • Pass the serialized request as a rooted JS value instead of interpolating it into source text.
  • Warmup path

    • Run JIT warmup through the same direct-call path used by real requests.
    • Remove generated JavaScript loop construction from warmup.
let args = HandleValueArray::from(req_arg.handle().into_handle());

JS_CallFunctionName(
    cx,
    global,
    CALL_FETCH_NAME.as_ptr() as *const std::os::raw::c_char,
    &args,
    rval.handle_mut(),
)

@VrilLabs
Copy link
Copy Markdown
Contributor

Summary:

Optimized SpiderMonkey fetch dispatch by avoiding per-request evaluate_script.
Benchmarked SpiderMonkey ahead of Boa on dynamic handler:

  • Boa: 75,941.875 rps
  • SpiderMonkey: 86,582.25 rps

Validated:

cargo build
cargo test -p helios
cargo check -p helios --features spidermonkey
cargo fmt --check

parallel_validation: code review completed; CodeQL timed out per tool limit.

@VrilLabs VrilLabs marked this pull request as ready for review May 30, 2026 09:56
Copilot AI review requested due to automatic review settings May 30, 2026 09:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR wires an optional native SpiderMonkey backend into HELIOS and changes the SpiderMonkey fetch path to call the registered dispatcher directly rather than re-evaluating generated JavaScript per request.

Changes:

  • Adds mozjs as the optional dependency behind the spidermonkey feature.
  • Implements a SpiderMonkey-backed engine path in xdr.rs, including direct JS_CallFunctionName dispatch and warmup.
  • Switches the CLI to select SpiderMonkey when the feature is enabled; several other files are formatting-only changes.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
rs/helios/src/xdr.rs Adds the SpiderMonkey backend implementation and tests.
rs/helios/src/main.rs Selects Boa or SpiderMonkey as the active CLI engine based on feature flags.
rs/helios/Cargo.toml Adds optional mozjs dependency to the spidermonkey feature.
rs/Cargo.lock Records the new SpiderMonkey dependency graph.
rs/helios/src/boa_backend.rs Formatting-only changes.
rs/helios/src/wizer_build.rs Formatting-only changes.
rs/helios/src/wit_host.rs Formatting-only changes.
rs/helios/src/webtransport.rs Formatting-only changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rs/helios/src/xdr.rs Outdated
Comment on lines +842 to +843
headers: req.headers || [],
body: req.body || []
Comment thread rs/helios/src/xdr.rs Outdated
Comment on lines +558 to +562
pub(super) unsafe fn shutdown_engine_for_tests() {
if let Some(ptr) = ENGINE.get().copied().filter(|ptr| *ptr != 0) {
drop(unsafe { Box::from_raw(ptr as *mut JSEngine) });
}
}
Comment thread rs/helios/src/xdr.rs
Comment on lines +853 to +855
if (!captured) {
throw new Error('fetch handler did not call event.respondWith()');
}
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.

3 participants