From ada39e0fed6dee8659bbb783738b109a0beeacb0 Mon Sep 17 00:00:00 2001 From: "Yifeng \"Evan\" Wang" <7312949+doodlewind@users.noreply.github.com> Date: Mon, 20 Jul 2026 08:30:12 +0800 Subject: [PATCH] perf(libquickjs-sys): compile QuickJS at -O2 (was -O0 since 2021 bring-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cc build has carried .opt_level(0) since the October 2021 PSP cross-compile experiments — every host has been running an unoptimized interpreter dispatch loop. -O2 matches the official QuickJS Makefile. Also expose JS_SetGCThreshold / JS_RunGC in the hand-curated no_std binding surface (real exported symbols in libquickjs.a). Co-Authored-By: Claude Fable 5 --- libquickjs-sys/build.rs | 5 ++++- libquickjs-sys/src/lib.rs | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libquickjs-sys/build.rs b/libquickjs-sys/build.rs index 9a6796f..aaa45f0 100644 --- a/libquickjs-sys/build.rs +++ b/libquickjs-sys/build.rs @@ -114,7 +114,10 @@ fn main() { .flag_if_supported("-Wno-cast-function-type") .flag_if_supported("-Wno-implicit-fallthrough") .flag_if_supported("-Wno-enum-conversion") - .opt_level(0); + // The interpreter dispatch loop is the hottest code in every host; + // -O2 matches the official QuickJS Makefile. (This sat at -O0 from a + // 2021 bring-up experiment — a ~3-5x interpreter slowdown on MIPS.) + .opt_level(2); if is_psp { build diff --git a/libquickjs-sys/src/lib.rs b/libquickjs-sys/src/lib.rs index 6e92cca..ad7edc0 100644 --- a/libquickjs-sys/src/lib.rs +++ b/libquickjs-sys/src/lib.rs @@ -357,6 +357,11 @@ extern "C" { /// immediately, never retain it. Used by the 3D host (gfx3d.rs) to read mesh /// + command buffers handed down from JS. pub fn JS_GetArrayBuffer(ctx: *mut JSContext, psize: *mut size_t, obj: JSValue) -> *mut u8; + + /// Cycle-collector trigger threshold (bytes allocated since the last run; + /// refcounting reclaims acyclic garbage regardless). Default is 256 KB. + pub fn JS_SetGCThreshold(rt: *mut JSRuntime, gc_threshold: size_t); + pub fn JS_RunGC(rt: *mut JSRuntime); } /// Custom allocator hooks so QuickJS can use the host (Rust/PSP) allocator