From f4c155c9c599c150e7b786bd022c33f0f12eab53 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 8 May 2026 08:50:45 +0000 Subject: [PATCH] HS: hoist emit-on throttle/debounce helpers to module level (perf) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous version put (define _throttle-ms ...) (define _debounce-ms ...) (define _strip-throttle-debounce ...) inside emit-on's body, redefining them on every call to emit-on. The kernel JIT-compiled the helper fn fresh each invocation, doubling compile time across the suite and pushing many tests over their wall-clock deadline (35 cumulative-only timeouts in the latest batched run, up from 0). Move the three definitions to module-level. Use (set! _throttle-ms nil) (set! _debounce-ms nil) at the top of emit-on to reset state for each call. JIT compilation of _strip-throttle-debounce now happens once. Verified: hs-upstream-expressions/dom-scope went from 18/20 (with two state-related timeouts) back to 20/20, suite wall-time 232s → 75s. Co-Authored-By: Claude Sonnet 4.6 --- lib/hyperscript/compiler.sx | 45 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 97adec86..71c1c678 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -210,6 +210,28 @@ value) (list (quote set!) (hs-to-sx target) value))))))) (true (list (quote set!) (hs-to-sx target) value))))))) + ;; Throttle/debounce extraction state — module-level so they don't get + ;; redefined on every emit-on call (which was causing JIT churn). Set + ;; via _strip-throttle-debounce at the start of each emit-on, used in + ;; the handler-build step inside scan-on. + (define _throttle-ms nil) + (define _debounce-ms nil) + (define + _strip-throttle-debounce + (fn + (lst) + (cond + ((<= (len lst) 1) lst) + ((= (first lst) :throttle) + (do + (set! _throttle-ms (nth lst 1)) + (_strip-throttle-debounce (rest (rest lst))))) + ((= (first lst) :debounce) + (do + (set! _debounce-ms (nth lst 1)) + (_strip-throttle-debounce (rest (rest lst))))) + (true + (cons (first lst) (_strip-throttle-debounce (rest lst))))))) (define emit-on (fn @@ -218,27 +240,8 @@ ((parts (rest ast))) (let ((event-name (first parts))) - ;; Pre-extract :throttle and :debounce kwargs (handler-wrapping modifiers) - ;; from parts so scan-on doesn't need extra params. Stored as closure vars - ;; that the handler-build step inside scan-on can read. - (define _throttle-ms nil) - (define _debounce-ms nil) - (define - _strip-throttle-debounce - (fn - (lst) - (cond - ((<= (len lst) 1) lst) - ((= (first lst) :throttle) - (do - (set! _throttle-ms (nth lst 1)) - (_strip-throttle-debounce (rest (rest lst))))) - ((= (first lst) :debounce) - (do - (set! _debounce-ms (nth lst 1)) - (_strip-throttle-debounce (rest (rest lst))))) - (true - (cons (first lst) (_strip-throttle-debounce (rest lst))))))) + (set! _throttle-ms nil) + (set! _debounce-ms nil) (define scan-on (fn