From 8479a6581d023b511451891f59f43733282cc3c1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 28 Dec 2021 23:21:56 +0100 Subject: [PATCH] :zap: Make matrix use native doubles. Increases 300x the performance of multiply on the JVM platform. --- common/src/app/common/geom/matrix.cljc | 7 ++++++- common/src/app/common/transit.cljc | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index 695925bf94..b03cba0d4e 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -14,7 +14,12 @@ ;; --- Matrix Impl -(defrecord Matrix [a b c d e f] +(defrecord Matrix [^double a + ^double b + ^double c + ^double d + ^double e + ^double f] Object (toString [_] (str "matrix(" a "," b "," c "," d "," e "," f ")"))) diff --git a/common/src/app/common/transit.cljc b/common/src/app/common/transit.cljc index e6d90e18d9..4333051ee7 100644 --- a/common/src/app/common/transit.cljc +++ b/common/src/app/common/transit.cljc @@ -72,7 +72,15 @@ (fn [v] (into {} v)))) (def matrix-read-handler - (t/read-handler gmt/map->Matrix)) + (t/read-handler (fn [data] + #?(:cljs (gmt/map->Matrix data) + :clj (let [{:keys [a b c d e f]} data] + (gmt/matrix (double a) + (double b) + (double c) + (double d) + (double e) + (double f))))))) ;; --- ORDERED SET