Permalink
Browse files

CLJS-709: optimize clj->js for non-map collection case to array

  • Loading branch information...
1 parent 569c3c2 commit 1a8faf57dde2a0096478a5e7b8e7d086921ceaf2 @swannodette swannodette committed Dec 3, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/cljs/cljs/core.cljs
View
@@ -7146,7 +7146,10 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
(doseq [[k v] x]
(aset m (key->js k) (clj->js v)))
m)
- (coll? x) (apply array (map clj->js x))
+ (coll? x) (let [arr (array)]
+ (doseq [x (map clj->js x)]
+ (.push arr x))
+ arr)
:else x))))
(defprotocol IEncodeClojure

3 comments on commit 1a8faf5

Contributor

sgrove commented on 1a8faf5 Dec 3, 2013

Any checks on performance difference?

Member

swannodette replied Dec 3, 2013

Nope, but I'd expect this to be near 2X faster if not more, the previous code path required cloning the array twice and going through apply which is not fast.

The performances are still too low for some use cases, for instance when interfacing with React or om where render() need to be as fast possible and only native Arrays are understood by the library.
Any chance there could be more focused methods usable in tight loops? I.e non recursive toArray, toObject, etc

Please sign in to comment.