Perf: optimize coll freezing via new enc/reduce-n
- Take advantage of clojure.lang.LongRange - Avoid unnecessary temp `[k v]` (map entry) constructions
This commit is contained in:
parent
d154ada9e4
commit
7adad2240c
2 changed files with 21 additions and 16 deletions
|
|
@ -15,7 +15,7 @@
|
||||||
:dependencies
|
:dependencies
|
||||||
[[org.clojure/clojure "1.5.1"]
|
[[org.clojure/clojure "1.5.1"]
|
||||||
[org.clojure/tools.reader "0.10.0"]
|
[org.clojure/tools.reader "0.10.0"]
|
||||||
[com.taoensso/encore "2.36.2"]
|
[com.taoensso/encore "2.41.0"]
|
||||||
[org.iq80.snappy/snappy "0.4"]
|
[org.iq80.snappy/snappy "0.4"]
|
||||||
[org.tukaani/xz "1.5"]
|
[org.tukaani/xz "1.5"]
|
||||||
[net.jpountz.lz4/lz4 "1.3"]]
|
[net.jpountz.lz4/lz4 "1.3"]]
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
IRecord ISeq]))
|
IRecord ISeq]))
|
||||||
|
|
||||||
(if (vector? enc/encore-version)
|
(if (vector? enc/encore-version)
|
||||||
(enc/assert-min-encore-version [2 16 0])
|
(enc/assert-min-encore-version [2 41 0])
|
||||||
(enc/assert-min-encore-version 2.16))
|
(enc/assert-min-encore-version 2.41))
|
||||||
|
|
||||||
;;;; Nippy data format
|
;;;; Nippy data format
|
||||||
;; * 4-byte header (Nippy v2.x+) (may be disabled but incl. by default) [1]
|
;; * 4-byte header (Nippy v2.x+) (may be disabled but incl. by default) [1]
|
||||||
|
|
@ -473,23 +473,28 @@
|
||||||
(defn read-utf8 ^String [^DataInput in] (String. (read-bytes in) "UTF-8"))
|
(defn read-utf8 ^String [^DataInput in] (String. (read-bytes in) "UTF-8"))
|
||||||
(defn read-sm-utf8 ^String [^DataInput in] (String. (read-sm-bytes in) "UTF-8"))
|
(defn read-sm-utf8 ^String [^DataInput in] (String. (read-sm-bytes in) "UTF-8"))
|
||||||
|
|
||||||
(defn read-coll [^DataInput in to-coll]
|
(defn- -read-coll [^DataInput in to-coll ^long n]
|
||||||
(enc/repeatedly-into to-coll (.readInt in) (fn [] (thaw-from-in! in))))
|
(if (and (> n 10) (enc/editable? to-coll))
|
||||||
|
(persistent!
|
||||||
|
(enc/reduce-n (fn [acc _] (conj! acc (thaw-from-in! in)))
|
||||||
|
(transient to-coll) n))
|
||||||
|
|
||||||
(defn read-sm-coll [^DataInput in to-coll]
|
(enc/reduce-n (fn [acc _] (conj acc (thaw-from-in! in))) to-coll n)))
|
||||||
(enc/repeatedly-into to-coll (.readByte in) (fn [] (thaw-from-in! in))))
|
|
||||||
|
|
||||||
(defn read-kvs [^DataInput in to-coll]
|
(defn- -read-kvs [^DataInput in to-coll ^long n]
|
||||||
(enc/repeatedly-into to-coll (.readInt in)
|
(if (and (> n 10) (enc/editable? to-coll))
|
||||||
(fn [] [(thaw-from-in! in) (thaw-from-in! in)])))
|
(persistent!
|
||||||
|
(enc/reduce-n (fn [acc _] (assoc! acc (thaw-from-in! in) (thaw-from-in! in)))
|
||||||
|
(transient to-coll) n))
|
||||||
|
|
||||||
(defn read-sm-kvs [^DataInput in to-coll]
|
(enc/reduce-n (fn [acc _] (assoc acc (thaw-from-in! in) (thaw-from-in! in)))
|
||||||
(enc/repeatedly-into to-coll (.readByte in)
|
to-coll n)))
|
||||||
(fn [] [(thaw-from-in! in) (thaw-from-in! in)])))
|
|
||||||
|
|
||||||
(defn read-kvs-depr1 [^DataInput in to-coll]
|
(defn read-coll [^DataInput in to-coll] (-read-coll in to-coll (.readInt in)))
|
||||||
(enc/repeatedly-into to-coll (quot (.readInt in) 2)
|
(defn read-sm-coll [^DataInput in to-coll] (-read-coll in to-coll (.readByte in)))
|
||||||
(fn [] [(thaw-from-in! in) (thaw-from-in! in)])))
|
(defn read-kvs [^DataInput in to-coll] (-read-kvs in to-coll (.readInt in)))
|
||||||
|
(defn read-sm-kvs [^DataInput in to-coll] (-read-kvs in to-coll (.readByte in)))
|
||||||
|
(defn read-kvs-depr1 [^DataInput in to-coll] (-read-kvs in to-coll (quot (.readInt in) 2)))
|
||||||
|
|
||||||
(def ^:private class-method-sig (into-array Class [IPersistentMap]))
|
(def ^:private class-method-sig (into-array Class [IPersistentMap]))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue