Types: add dedicated 2 and 3 tuple type
This commit is contained in:
parent
7adad2240c
commit
d327f0ff38
3 changed files with 31 additions and 6 deletions
|
|
@ -15,7 +15,7 @@
|
|||
:dependencies
|
||||
[[org.clojure/clojure "1.5.1"]
|
||||
[org.clojure/tools.reader "0.10.0"]
|
||||
[com.taoensso/encore "2.41.0"]
|
||||
[com.taoensso/encore "2.42.0"]
|
||||
[org.iq80.snappy/snappy "0.4"]
|
||||
[org.tukaani/xz "1.5"]
|
||||
[net.jpountz.lz4/lz4 "1.3"]]
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@
|
|||
(def ^:const id-sm-set (byte 111)) ; ''
|
||||
(def ^:const id-sm-map (byte 112)) ; ''
|
||||
;;
|
||||
;; TODO Additional optimizations (types) for 2-vecs and 3-vecs?
|
||||
(def ^:const id-2-vec (byte 113))
|
||||
(def ^:const id-3-vec (byte 114))
|
||||
|
||||
;;; DEPRECATED (old types will be supported only for thawing)
|
||||
(def ^:const id-reader-depr1 (byte 1)) ; v0.9.2+ for +64k support
|
||||
|
|
@ -262,9 +263,22 @@
|
|||
(freeze-to-out! out v))
|
||||
coll)))
|
||||
|
||||
(defn write-ided-vec [out v] (write-ided-coll out id-sm-vec id-vec v))
|
||||
;; (defn write-ided-vec [out v] (write-ided-coll out id-sm-vec id-vec v))
|
||||
(defn write-ided-set [out s] (write-ided-coll out id-sm-set id-set s))
|
||||
(defn write-ided-map [out m] (write-ided-kvs out id-sm-map id-map m))
|
||||
(defn write-ided-vec [^DataOutput out v]
|
||||
(let [cnt (count v)]
|
||||
(cond
|
||||
(== cnt 2) (write-id out id-2-vec)
|
||||
(== cnt 3) (write-id out id-3-vec)
|
||||
(byte-sized? cnt)
|
||||
(do (write-id out id-sm-vec)
|
||||
(.writeByte out cnt))
|
||||
:else
|
||||
(do (write-id out id-vec)
|
||||
(.writeInt out cnt)))
|
||||
|
||||
(enc/run!* (fn [in] (freeze-to-out! out in)) v)))
|
||||
|
||||
(defmacro ^:private freezer* [type & body]
|
||||
`(extend-type ~type
|
||||
|
|
@ -290,7 +304,7 @@
|
|||
(freezer* PersistentTreeSet (write-ided-coll out nil id-sorted-set x))
|
||||
(freezer* PersistentTreeMap (write-ided-kvs out nil id-sorted-map x))
|
||||
(freezer* APersistentMap (write-ided-kvs out id-sm-map id-map x))
|
||||
(freezer* APersistentVector (write-ided-coll out id-sm-vec id-vec x))
|
||||
(freezer* APersistentVector (write-ided-vec out x))
|
||||
(freezer* APersistentSet (write-ided-coll out id-sm-set id-set x))
|
||||
|
||||
;; No APersistentList:
|
||||
|
|
@ -581,6 +595,10 @@
|
|||
|
||||
id-vec (read-coll in [])
|
||||
id-sm-vec (read-sm-coll in [])
|
||||
id-2-vec [(thaw-from-in! in) (thaw-from-in! in)]
|
||||
id-3-vec [(thaw-from-in! in) (thaw-from-in! in)
|
||||
(thaw-from-in! in)]
|
||||
|
||||
id-set (read-coll in #{})
|
||||
id-sm-set (read-sm-coll in #{})
|
||||
id-map (read-kvs in {})
|
||||
|
|
|
|||
|
|
@ -68,8 +68,15 @@
|
|||
(set! *unchecked-math* false)
|
||||
;; (bench {:reader? true :lzma2? true :fressian? true :laps 3})
|
||||
;; (bench {:laps 4})
|
||||
;; (bench {:laps 2 :lzma2? true})
|
||||
;; (bench {:laps 2})
|
||||
|
||||
;;; 2016 Mar 8, v2.12.0-SNAPSHOT, new hardware
|
||||
{:reader {:round 51217, :freeze 16729, :thaw 34488, :size 27698}}
|
||||
{:lzma2 {:round 42066, :freeze 27249, :thaw 14817, :size 11232}}
|
||||
{:fressian {:round 6594, :freeze 4789, :thaw 1805, :size 16985}}
|
||||
{:encrypted {:round 4664, :freeze 2856, :thaw 1808, :size 16132}}
|
||||
{:default {:round 4127, :freeze 2546, :thaw 1581, :size 16113}}
|
||||
{:fast1 {:round 3541, :freeze 2024, :thaw 1517, :size 16975}}
|
||||
{:fast2 {:round 3497, :freeze 2018, :thaw 1479, :size 16971}}
|
||||
|
||||
;;; 2015 Oct 6, v2.11.0-alpha4
|
||||
{:reader {:round 73409, :freeze 21823, :thaw 51586, :size 27672}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue