mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 22:53:02 +00:00
Merge pull request #7119 from penpot/niwinz-develop-type-hints
⚡ Add several performance enhancements
This commit is contained in:
@@ -41,8 +41,10 @@
|
||||
[datoteka.fs :as fs]
|
||||
[datoteka.io :as io])
|
||||
(:import
|
||||
java.io.File
|
||||
java.io.InputStream
|
||||
java.io.OutputStreamWriter
|
||||
java.lang.AutoCloseable
|
||||
java.util.zip.ZipEntry
|
||||
java.util.zip.ZipFile
|
||||
java.util.zip.ZipOutputStream))
|
||||
@@ -251,9 +253,9 @@
|
||||
(write-entry! output path params)
|
||||
|
||||
(with-open [input (sto/get-object-data storage sobject)]
|
||||
(.putNextEntry output (ZipEntry. (str "objects/" id ext)))
|
||||
(.putNextEntry ^ZipOutputStream output (ZipEntry. (str "objects/" id ext)))
|
||||
(io/copy input output :size (:size sobject))
|
||||
(.closeEntry output))))))
|
||||
(.closeEntry ^ZipOutputStream output))))))
|
||||
|
||||
(defn- export-file
|
||||
[{:keys [::file-id ::output] :as cfg}]
|
||||
@@ -447,7 +449,7 @@
|
||||
(defn- read-manifest
|
||||
[^ZipFile input]
|
||||
(let [entry (get-zip-entry input "manifest.json")]
|
||||
(with-open [reader (zip-entry-reader input entry)]
|
||||
(with-open [^AutoCloseable reader (zip-entry-reader input entry)]
|
||||
(let [manifest (json/read reader :key-fn json/read-kebab-key)]
|
||||
(decode-manifest manifest)))))
|
||||
|
||||
@@ -537,12 +539,12 @@
|
||||
|
||||
(defn- read-entry
|
||||
[^ZipFile input entry]
|
||||
(with-open [reader (zip-entry-reader input entry)]
|
||||
(with-open [^AutoCloseable reader (zip-entry-reader input entry)]
|
||||
(json/read reader :key-fn json/read-kebab-key)))
|
||||
|
||||
(defn- read-plain-entry
|
||||
[^ZipFile input entry]
|
||||
(with-open [reader (zip-entry-reader input entry)]
|
||||
(with-open [^AutoCloseable reader (zip-entry-reader input entry)]
|
||||
(json/read reader)))
|
||||
|
||||
(defn- read-file
|
||||
@@ -1006,8 +1008,8 @@
|
||||
(try
|
||||
(l/info :hint "start exportation" :export-id (str id))
|
||||
(binding [bfc/*state* (volatile! (bfc/initial-state))]
|
||||
(with-open [output (io/output-stream output)]
|
||||
(with-open [output (ZipOutputStream. output)]
|
||||
(with-open [^AutoCloseable output (io/output-stream output)]
|
||||
(with-open [^AutoCloseable output (ZipOutputStream. output)]
|
||||
(let [cfg (assoc cfg ::output output)]
|
||||
(export-files cfg)
|
||||
(export-storage-objects cfg)))))
|
||||
@@ -1051,7 +1053,7 @@
|
||||
|
||||
(l/info :hint "import: started" :id (str id))
|
||||
(try
|
||||
(with-open [input (ZipFile. (fs/file input))]
|
||||
(with-open [input (ZipFile. ^File (fs/file input))]
|
||||
(import-files (assoc cfg ::bfc/input input)))
|
||||
|
||||
(catch Throwable cause
|
||||
@@ -1066,6 +1068,6 @@
|
||||
|
||||
(defn get-manifest
|
||||
[path]
|
||||
(with-open [input (ZipFile. (fs/file path))]
|
||||
(with-open [^AutoCloseable input (ZipFile. ^File (fs/file path))]
|
||||
(-> (read-manifest input)
|
||||
(validate-manifest))))
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
(println "event:" (d/name name))
|
||||
(println "data:" (t/encode-str data {:type :json-verbose}))
|
||||
(println))]
|
||||
(.getBytes data "UTF-8"))
|
||||
(.getBytes ^String data "UTF-8"))
|
||||
(catch Throwable cause
|
||||
(l/err :hint "unexpected error on encoding value on sse stream"
|
||||
:cause cause)
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
(defn- parse-svg
|
||||
[text]
|
||||
(let [text (strip-doctype text)]
|
||||
(dm/with-open [istream (IOUtils/toInputStream text "UTF-8")]
|
||||
(dm/with-open [istream (IOUtils/toInputStream ^String text "UTF-8")]
|
||||
(xml/parse istream secure-parser-factory))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -212,8 +212,8 @@
|
||||
deleted 0]
|
||||
(if-let [chunk (get-chunk pool)]
|
||||
(let [[nfo ndo] (db/tx-run! cfg process-chunk! chunk)]
|
||||
(recur (+ freezed nfo)
|
||||
(+ deleted ndo)))
|
||||
(recur (long (+ freezed nfo))
|
||||
(long (+ deleted ndo))))
|
||||
(do
|
||||
(l/inf :hint "task finished"
|
||||
:to-freeze freezed
|
||||
|
||||
@@ -313,7 +313,7 @@
|
||||
(db/exec-one! conn ["SET LOCAL rules.deletion_protection TO off"])
|
||||
(proc-fn cfg)))]
|
||||
(if (pos? result)
|
||||
(recur (+ total result))
|
||||
(recur (long (+ total result)))
|
||||
total))))
|
||||
|
||||
(defmethod ig/assert-key ::handler
|
||||
@@ -335,7 +335,7 @@
|
||||
(if-let [proc-fn (first procs)]
|
||||
(let [result (execute-proc! cfg proc-fn)]
|
||||
(recur (rest procs)
|
||||
(+ total result)))
|
||||
(long (+ total result))))
|
||||
(do
|
||||
(l/inf :hint "task finished" :deleted total)
|
||||
{:processed total}))))))
|
||||
|
||||
@@ -20,42 +20,42 @@
|
||||
(if (:ns &env)
|
||||
`(.getInt8 ~target ~offset true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(long (.get ~target ~offset)))))
|
||||
`(long (.get ~target (unchecked-int ~offset))))))
|
||||
|
||||
(defmacro read-unsigned-byte
|
||||
[target offset]
|
||||
(if (:ns &env)
|
||||
`(.getUint8 ~target ~offset true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(bit-and (long (.get ~target ~offset)) 0xff))))
|
||||
`(bit-and (long (.get ~target (unchecked-int ~offset))) 0xff))))
|
||||
|
||||
(defmacro read-bool
|
||||
[target offset]
|
||||
(if (:ns &env)
|
||||
`(== 1 (.getInt8 ~target ~offset true))
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(== 1 (.get ~target ~offset)))))
|
||||
`(== 1 (.get ~target (unchecked-int ~offset))))))
|
||||
|
||||
(defmacro read-short
|
||||
[target offset]
|
||||
(if (:ns &env)
|
||||
`(.getInt16 ~target ~offset true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.getShort ~target ~offset))))
|
||||
`(.getShort ~target (unchecked-int ~offset)))))
|
||||
|
||||
(defmacro read-int
|
||||
[target offset]
|
||||
(if (:ns &env)
|
||||
`(.getInt32 ~target ~offset true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(long (.getInt ~target ~offset)))))
|
||||
`(long (.getInt ~target (unchecked-int ~offset))))))
|
||||
|
||||
(defmacro read-float
|
||||
[target offset]
|
||||
(if (:ns &env)
|
||||
`(.getFloat32 ~target ~offset true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(double (.getFloat ~target ~offset)))))
|
||||
`(double (.getFloat ~target (unchecked-int ~offset))))))
|
||||
|
||||
(defmacro read-uuid
|
||||
[target offset]
|
||||
@@ -69,8 +69,8 @@
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(try
|
||||
(.order ~target ByteOrder/BIG_ENDIAN)
|
||||
(let [msb# (.getLong ~target (+ ~offset 0))
|
||||
lsb# (.getLong ~target (+ ~offset 8))]
|
||||
(let [msb# (.getLong ~target (unchecked-int (+ ~offset 0)))
|
||||
lsb# (.getLong ~target (unchecked-int (+ ~offset 8)))]
|
||||
(java.util.UUID. (long msb#) (long lsb#)))
|
||||
(finally
|
||||
(.order ~target ByteOrder/LITTLE_ENDIAN))))))
|
||||
@@ -80,7 +80,7 @@
|
||||
(if (:ns &env)
|
||||
`(.setInt8 ~target ~offset ~value true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.put ~target ~offset (unchecked-byte ~value)))))
|
||||
`(.put ~target (unchecked-int ~offset) (unchecked-byte ~value)))))
|
||||
|
||||
(defmacro write-u8
|
||||
[target offset value]
|
||||
@@ -94,21 +94,21 @@
|
||||
(if (:ns &env)
|
||||
`(.setInt8 ~target ~offset (if ~value 0x01 0x00) true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.put ~target ~offset (unchecked-byte (if ~value 0x01 0x00))))))
|
||||
`(.put ~target (unchecked-int ~offset) (unchecked-byte (if ~value 0x01 0x00))))))
|
||||
|
||||
(defmacro write-short
|
||||
[target offset value]
|
||||
(if (:ns &env)
|
||||
`(.setInt16 ~target ~offset ~value true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.putShort ~target ~offset (unchecked-short ~value)))))
|
||||
`(.putShort ~target (unchecked-int ~offset) (unchecked-short ~value)))))
|
||||
|
||||
(defmacro write-int
|
||||
[target offset value]
|
||||
(if (:ns &env)
|
||||
`(.setInt32 ~target ~offset ~value true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.putInt ~target ~offset (unchecked-int ~value)))))
|
||||
`(.putInt ~target (unchecked-int ~offset) (unchecked-int ~value)))))
|
||||
|
||||
(defmacro write-u32
|
||||
[target offset value]
|
||||
@@ -127,7 +127,7 @@
|
||||
(if (:ns &env)
|
||||
`(.setFloat32 ~target ~offset ~value true)
|
||||
(let [target (with-meta target {:tag 'java.nio.ByteBuffer})]
|
||||
`(.putFloat ~target ~offset (unchecked-float ~value)))))
|
||||
`(.putFloat ~target (unchecked-int ~offset) (unchecked-float ~value)))))
|
||||
|
||||
(defmacro write-f32
|
||||
"Idiomatic alias for `write-float`."
|
||||
@@ -147,8 +147,8 @@
|
||||
value (with-meta value {:tag 'java.util.UUID})]
|
||||
`(try
|
||||
(.order ~target ByteOrder/BIG_ENDIAN)
|
||||
(.putLong ~target (+ ~offset 0) (.getMostSignificantBits ~value))
|
||||
(.putLong ~target (+ ~offset 8) (.getLeastSignificantBits ~value))
|
||||
(.putLong ~target (unchecked-int (+ ~offset 0)) (.getMostSignificantBits ~value))
|
||||
(.putLong ~target (unchecked-int (+ ~offset 8)) (.getLeastSignificantBits ~value))
|
||||
(finally
|
||||
(.order ~target ByteOrder/LITTLE_ENDIAN))))))
|
||||
|
||||
|
||||
@@ -25,16 +25,7 @@
|
||||
|
||||
;; --- Matrix Impl
|
||||
|
||||
(defn format-precision
|
||||
[mtx precision]
|
||||
(when mtx
|
||||
(dm/fmt "matrix(%, %, %, %, %, %)"
|
||||
(mth/to-fixed (.-a mtx) precision)
|
||||
(mth/to-fixed (.-b mtx) precision)
|
||||
(mth/to-fixed (.-c mtx) precision)
|
||||
(mth/to-fixed (.-d mtx) precision)
|
||||
(mth/to-fixed (.-e mtx) precision)
|
||||
(mth/to-fixed (.-f mtx) precision))))
|
||||
(declare format-precision)
|
||||
|
||||
(cr/defrecord Matrix [^double a
|
||||
^double b
|
||||
@@ -46,6 +37,17 @@
|
||||
(toString [this]
|
||||
(format-precision this precision)))
|
||||
|
||||
(defn format-precision
|
||||
[mtx precision]
|
||||
(when mtx
|
||||
(dm/fmt "matrix(%, %, %, %, %, %)"
|
||||
(mth/to-fixed (.-a ^Matrix mtx) precision)
|
||||
(mth/to-fixed (.-b ^Matrix mtx) precision)
|
||||
(mth/to-fixed (.-c ^Matrix mtx) precision)
|
||||
(mth/to-fixed (.-d ^Matrix mtx) precision)
|
||||
(mth/to-fixed (.-e ^Matrix mtx) precision)
|
||||
(mth/to-fixed (.-f ^Matrix mtx) precision))))
|
||||
|
||||
(defn matrix?
|
||||
"Return true if `v` is Matrix instance."
|
||||
[v]
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
[_ modif-tree]
|
||||
(reduce set-child-modifiers [layout-line modif-tree] children)]
|
||||
(recur modif-tree (first pending) (rest pending) to-idx))
|
||||
(recur modif-tree (first pending) (rest pending) (long to-idx)))
|
||||
|
||||
modif-tree)))))
|
||||
|
||||
|
||||
@@ -255,10 +255,10 @@
|
||||
(if-let [pt (first pts)]
|
||||
(let [x (dm/get-prop pt :x)
|
||||
y (dm/get-prop pt :y)]
|
||||
(recur (mth/min minx x)
|
||||
(mth/min miny y)
|
||||
(mth/max maxx x)
|
||||
(mth/max maxy y)
|
||||
(recur (double (mth/min minx x))
|
||||
(double (mth/min miny y))
|
||||
(double (mth/max maxx x))
|
||||
(double (mth/max maxy y))
|
||||
(rest pts)))
|
||||
(when (d/num? minx miny maxx maxy)
|
||||
(make-rect minx miny (- maxx minx) (- maxy miny)))))))
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
(rest children)))))]
|
||||
|
||||
(recur next-areas
|
||||
(+ from-idx (:num-children current-line))
|
||||
(+ from-idx (long (:num-children current-line)))
|
||||
(+ (:x line-area) (:width line-area))
|
||||
(+ (:y line-area) (:height line-area))
|
||||
(rest lines)))))))
|
||||
|
||||
@@ -393,7 +393,7 @@
|
||||
min-fr
|
||||
(let [{:keys [size type value]} (first tracks)
|
||||
min-fr (if (= type :flex) (max min-fr (/ size value)) min-fr)]
|
||||
(recur (rest tracks) min-fr)))))
|
||||
(recur (rest tracks) (double min-fr))))))
|
||||
|
||||
(defn calc-layout-data
|
||||
([parent transformed-parent-bounds children bounds objects]
|
||||
|
||||
@@ -403,7 +403,7 @@
|
||||
|
||||
(if (>= to 1)
|
||||
result
|
||||
(recur to result))))))
|
||||
(recur (long to) result))))))
|
||||
|
||||
(defn curve-split
|
||||
"Splits a curve into two at the given parametric value `t`.
|
||||
|
||||
@@ -190,4 +190,4 @@
|
||||
(recur (first subpath)
|
||||
(rest subpath)
|
||||
first-point
|
||||
signed-area))))))
|
||||
(long signed-area)))))))
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
(gpt/point 20 65.2)
|
||||
(gpt/point 12 -10)]
|
||||
result (grc/points->rect points)
|
||||
expect {:x -1, :y -10, :width 21, :height 75.2}]
|
||||
expect {:x -1.0, :y -10.0, :width 21.0, :height 75.2}]
|
||||
|
||||
(t/is (= (:x expect) (:x result)))
|
||||
(t/is (= (:y expect) (:y result)))
|
||||
|
||||
Reference in New Issue
Block a user