Lazy JIT compilation: lambdas compile to bytecode on first call
Replace AOT adapter compilation with lazy JIT — each named lambda is compiled to VM bytecode on first call, cached in l_compiled field for subsequent calls. Compilation failures fall back to CEK gracefully. VM types (vm_code, vm_upvalue_cell, vm_closure) moved to sx_types.ml mutual recursion block. Lambda and Component records gain mutable l_compiled/c_compiled cache fields. jit_compile_lambda in sx_vm.ml wraps body as (fn (params) body), invokes spec/compiler.sx via CEK, extracts inner closure from OP_CLOSURE constant. JIT hooks in both paths: - vm_call: Lambda calls from compiled VM code - continue_with_call: Lambda calls from CEK step loop (injected by bootstrap.py post-processing) Pre-mark sentinel prevents re-entrancy (compile function itself was hanging when JIT'd mid-compilation). VM execution errors caught and fall back to CEK with sentinel marking. Also: add kbd/samp/var to HTML_TAGS, rebuild sx-browser.js, add page URL to sx-page-full-py timing log. Performance: first page 28s (JIT compiles 17 functions), subsequent pages 0.31s home / 0.71s wittgenstein (was 2.3s). All 1945 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -434,13 +434,13 @@ class OcamlBridge:
|
||||
skipped += 1
|
||||
_logger.warning("OCaml load skipped %s: %s",
|
||||
filepath, e)
|
||||
# Compile adapter to VM after all files loaded (inside lock)
|
||||
# Register JIT hook — lambdas compile on first call
|
||||
try:
|
||||
await self._send('(vm-compile-adapter)')
|
||||
await self._read_until_ok(ctx=None)
|
||||
_logger.info("VM adapter compiled — aser runs on bytecode VM")
|
||||
_logger.info("JIT hook registered — lambdas compile on first call")
|
||||
except OcamlBridgeError as e:
|
||||
_logger.warning("VM adapter compilation skipped: %s", e)
|
||||
_logger.warning("JIT hook registration skipped: %s", e)
|
||||
_logger.info("Loaded %d definitions from .sx files into OCaml kernel (%d skipped)",
|
||||
count, skipped)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user