Skip to content

Commit

Permalink
Extract body interpretation as an inline function
Browse files Browse the repository at this point in the history
;; Results interpretation body inline

lein test sci.performance
Testing reusable function result.
Evaluation count : 18228 in 6 samples of 3038 calls.
             Execution time mean : 34.552298 µs
    Execution time std-deviation : 1.253465 µs
   Execution time lower quantile : 32.660598 µs ( 2.5%)
   Execution time upper quantile : 35.494253 µs (97.5%)
                   Overhead used : 1.411180 ns


Ran 1 tests containing 0 assertions.
0 failures, 0 errors.

;; Results interpretation of body as inline function

lein test sci.performance
Testing reusable function result.
Evaluation count : 17478 in 6 samples of 2913 calls.
             Execution time mean : 35.173788 µs
    Execution time std-deviation : 1.636139 µs
   Execution time lower quantile : 32.530240 µs ( 2.5%)
   Execution time upper quantile : 36.825700 µs (97.5%)
                   Overhead used : 1.415773 ns


Ran 1 tests containing 0 assertions.
0 failures, 0 errors.
  • Loading branch information
jeroenvandijk committed Jun 11, 2020
1 parent 6c8852d commit 25ace7c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sci/impl/fns.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
{:sci.impl/keys [fixed-arity var-arg-name params body] :as _m}
fn-name macro? with-meta?]
(let [min-var-args-arity (when var-arg-name fixed-arity)

interpret-body (if (= 1 (count body))
(let [body-part1 (first body)]
(fn [ctx] (interpret ctx body-part1)))
(fn [ctx] (eval-do* ctx body)))

f (fn run-fn [& args]
(let [;; tried making bindings a transient, but saw no perf improvement (see #246)
bindings (:bindings ctx)
Expand All @@ -40,9 +46,7 @@
(throw-arity fn-name macro? args))
ret)))
ctx (assoc ctx :bindings bindings)
ret (if (= 1 (count body))
(interpret ctx (first body))
(eval-do* ctx body))
ret (interpret-body ctx)
;; m (meta ret)
recur? (instance? Recur ret)]
(if recur?
Expand Down

0 comments on commit 25ace7c

Please sign in to comment.