Browser JIT: compile SX lambdas to bytecode VM in WASM kernel

- Wire up jit_call_hook in sx_browser.ml (same pattern as server)
- Deferred JIT: _jit_enabled flag, enabled after boot-init completes
  (prevents "Undefined symbol" errors from compiling during .sx loading)
- enable-jit! native function called by sx-platform.js after boot
- sx-platform.js: async WASM kernel polling + JIT enable after init
- Error logging for JIT compile failures and runtime fallbacks

Performance: 858ms → 431ms (WASM CEK) → 101ms (WASM JIT)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 17:04:39 +00:00
parent c72a5af04d
commit 226c01bbf6
12 changed files with 76 additions and 5 deletions

View File

@@ -16,8 +16,7 @@
(function() {
"use strict";
var K = globalThis.SxKernel;
if (!K) { console.error("[sx-platform] SxKernel not found"); return; }
function boot(K) {
// ================================================================
// 8 FFI Host Primitives
@@ -340,6 +339,7 @@
var _doInit = function() {
loadWebStack();
Sx.init();
K.eval('(enable-jit!)');
};
if (document.readyState === "loading") {
@@ -349,4 +349,16 @@
}
}
} // end boot
// SxKernel is available synchronously (js_of_ocaml) or after async
// WASM init. Poll briefly to handle both cases.
var K = globalThis.SxKernel;
if (K) { boot(K); return; }
var tries = 0;
var poll = setInterval(function() {
K = globalThis.SxKernel;
if (K) { clearInterval(poll); boot(K); }
else if (++tries > 100) { clearInterval(poll); console.error("[sx-platform] SxKernel not found after 5s"); }
}, 50);
})();