This document covers the deployment-time concerns of running luna in production: which crate to pull, packaging shapes, configuration knobs, observability hooks, and graceful-shutdown patterns.
For build-time AOT compile (Lua source → standalone native binary)
see aot.md. For the threat model that frames each opt-in
see security.md. For embedding cookbooks see
embedding.md.
| Deployment shape | Crate | Notes |
|---|---|---|
| Static-linked native binary, frozen Lua source | luna-aot (build-time) → standalone binary |
No runtime crate needed on host |
Rust service embedding Vm, JIT enabled |
luna-jit |
Pulls Cranelift; cross-thread via feature = "send" |
Rust service embedding Vm, interpreter only |
luna-core |
Zero third-party deps; ~280 KiB compressed |
| WASM (browser / wasm runtimes) | luna-core + --target wasm32-wasip1 |
JIT off; io/os stubbed |
| Cross-thread fleet (tokio JoinSet, web workers) | luna-jit + feature = "send" |
See threading.md |
The four library crates (luna-core, luna-jit-derive, luna-jit,
luna-runtime-helpers) compose: luna-jit re-exports luna-core
- adds Cranelift + REPL, so you don't dual-pull.
luna-aotis build-time only; the binary it produces statically linksluna-runtime-helpers.
luna-aot compile service.lua --target x86_64-unknown-linux-gnu --out service
# ./service runs without luna on the hostSuitable for: edge functions, embedded devices, container images
where you don't want a Rust toolchain or luna install in the
image. The produced binary is fully self-contained (statically
linked); see aot.md for binary size + section
breakdown.
# Cargo.toml of the host crate
[dependencies]
luna-jit = { version = "1.3", default-features = false, features = [] }The default-features-off shape skips the REPL line editor (only
needed for interactive luna REPL). Service code wraps Vm:
let mut vm = luna_jit::Vm::new(luna_jit::LuaVersion::Lua55);
vm.open_os_io(); // or omit for sandboxed
let r: i64 = vm.eval("return 1 + 2").unwrap();See embedding.md for the full builder cookbook.
FROM scratch
COPY ./target/x86_64-unknown-linux-musl/release/service /service
ENTRYPOINT ["/service"]For the smallest possible image, build with
--target x86_64-unknown-linux-musl (statically linked against
musl, no glibc dependency). Add RUN strip /service before the
COPY in a multi-stage build to drop ~85% of __LINKEDIT from
the binary.
[dependencies]
luna-core = { version = "1.3" } # interp only — no Cranelift on wasmio.popen / os.execute are compiled out under wasm32-wasip1
(see commit e72a43e — --target cfg gating). Sandbox boundaries
come from the wasi runtime, not from luna.
Runtime tunables live on Vm:
| Knob | Default | When to change |
|---|---|---|
vm.set_jit_enabled(bool) |
true (luna-jit) |
Disable for predictable startup latency / debug repro |
vm.set_trace_jit_enabled(bool) |
true (v1.3 TA3) |
Disable to A/B trace vs no-trace perf |
vm.set_hot_threshold(u32) |
(interpreter heuristic) | Lower for hot-immediately workloads; raise for cold-data services |
vm.set_max_trace_len(u32) |
(per-recorder constant) | Raise for long unrolled loops; lower for diverse-shape recording |
vm.allow_bytecode_loading() |
off | Enable only for fully trusted bytecode (security boundary) |
vm.open_os_io() |
not called | Trusted hosts only — see security.md |
vm.open_debug() |
not called | Debugging hooks, hot-path overhead |
vm.open_package() |
not called | Trusted source path config |
All knobs are sticky — set them once at startup, then eval.
luna doesn't log internally. Embedders hook via the debug hook
mechanism (PUC-compatible debug.sethook):
vm.set_rust_debug_hook(|vm, event| {
log::trace!("luna event: {:?} at pc={}", event, vm.current_pc());
});Per-thread; install on the main Vm and per-coroutine Vm clones
separately. See crates/luna-jit/examples/async_host.rs for the
async pattern.
Expose via host counters around Vm::eval:
let start = std::time::Instant::now();
let result = vm.eval(script);
metrics::histogram!("luna.eval.duration_ms", start.elapsed().as_millis() as f64);
metrics::counter!("luna.eval.error", if result.is_err() { 1 } else { 0 });For JIT-specific counters (trace_compiled_count, trace_aborted_count,
trace_dispatched_count), read via vm.trace_*_count() accessors;
useful for diagnosing why a workload isn't getting JIT speedup.
Peaks measured with dhat at v1.3 for five workloads:
| Workload | Peak | Steady |
|---|---|---|
| cold_start (empty Vm) | 33 KB | 31 KB |
| repl_idle (100 evals) | 71 KB | 69 KB |
| host_roots_churn (1k cycles) | 30 KB | 30 KB |
| alloc_collect (1M evals + 10 GC) | 1.0 MB | 523 KB |
| userdata_lifecycle (200 + finalizers) | 73 KB | 63 KB |
Use these as regression sentinels — a >5% steady-state increase on any workload should raise an alarm.
let result = vm.eval(script);
drop(vm); // runs all pending __gc finalizers via Heap::drop__gc finalizers always run on Vm::drop. If a finalizer panics,
the next finalizer still runs (PUC semantics; see
gc_finalizer_edges.rs::gc_finalizer_error_does_not_abort_program).
let fut = vm.eval_async(script);
// On shutdown:
drop(fut); // cancels the future; closeable iterators get __close
drop(vm); // runs remaining __gc finalizersEvalFuture::Drop runs to-be-closed (__close) handlers on
locals that have them — important for DB transactions or file
handles held in Lua locals.
For tokio-driven fleets:
tokio::time::timeout(Duration::from_secs(5), vm.eval_async(script)).awaitOn timeout, the future is dropped; the in-progress coroutine
gets __close cleanup. Pin that cancellation behavior in your own
integration tests against the luna version you ship.
feature = "send" on luna-jit enables the SendVm newtype —
Arc<UnsafeCell<Vm>> + RwLock outer shape, JIT path interp-only at
v1.3. See threading.md for the tokio JoinSet
pattern + per-request Vm pool sizing recipe.
The JIT does not cross threads: trace machine code does not move
between threads. The interpreter-only SendVm measured no overhead
(-1.8% to -0.3% on an M4 Max).
When upgrading between minor versions (1.x → 1.y):
- All
pubitems inlib.rs's exported tree are stable per the semver-major contract. lua.h-compatible C ABI insrc/capi.rsis stable.- Bytecode binary format (per dialect) is stable; PUC
.luacfiles load in/out across1.x. - Internal modules (JIT codegen, dispatcher hot-path, heap internals) may change without notice.
When upgrading across major versions (1.x → 2.0):
- See
migration-v1-to-v2.mdfor the per-area breaking-change checklist + migration recipes.
aot.md— single-binary deploy modeembedding.md— library embed cookbookthreading.md— cross-thread + tokiosecurity.md— threat model + sandbox boundariesbinary-size.md— per-crate + AOT-output budgetscompatibility.md— per-dialect feature matrixmigration-v1-to-v2.md— major-version upgrade checklist