From 25ace7c8941fe10f1c158d567936c730e91ac289 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Thu, 11 Jun 2020 11:04:41 +0200 Subject: [PATCH] Extract body interpretation as an inline function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ;; 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. --- src/sci/impl/fns.cljc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sci/impl/fns.cljc b/src/sci/impl/fns.cljc index 51197d88..36252d6d 100644 --- a/src/sci/impl/fns.cljc +++ b/src/sci/impl/fns.cljc @@ -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) @@ -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?