Skip to content

Commit 4fd16cd

Browse files
committed
Bypass apply in parser hot loop
When args is empty (the common case for simple grammar rules), call (func parser) directly instead of (apply func parser args). This avoids clojure.core/apply -> lang.Apply -> reflect.Value.call on every grammar rule invocation.
1 parent e339b80 commit 4fd16cd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

core/src/yamlstar/parser/parser.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@
162162
pos @(:pos parser)
163163
_ (receive parser func :try pos)
164164

165-
;; Call the function
166-
value (loop [v (apply func parser args)]
165+
;; Call the function — bypass clojure.core/apply
166+
;; when args is empty (common case) to avoid
167+
;; lang.Apply []any allocation and reflection.
168+
value (loop [v (if (empty? args)
169+
(func parser)
170+
(apply func parser args))]
167171
(if (or (fn? v) (vector? v))
168172
(recur (call parser v))
169173
v))]

0 commit comments

Comments
 (0)