HS: hoist emit-on throttle/debounce helpers to module level (perf)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s

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 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 08:50:45 +00:00
parent a9eb821cce
commit f4c155c9c5

View File

@@ -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