Fork me on GitHub
Daw-Ran Liou16:09:39

I’m trying to see if I can gain more performance by turning alias-map transformation into a transducer alias-map-xf:

(defn alias-map []
  (->> emojis
       (map (juxt identity :aliases))
       (mapcat (fn [[emoji aliases]] (map (fn [alias] [(keyword alias) emoji]) aliases)))
       (into {})))

(defn alias-map-xf []
  (into {} (comp
            (map (juxt :aliases identity))
            (mapcat (fn [[aliases emoji]]
                      (map (fn [alias] [(keyword alias) emoji]) aliases))))
emojis is a vector of emojis:
{:emojiChar "string"
 :aliases ["alias1" "alias2" ...]
In this example, I want to turn it into:
[:alias1 {:emojiChar "string"
              :aliases ["alias1" "alias2" ...]
[:alias2 {:emojiChar "string"
              :aliases ["alias1" "alias2" ...]
Then, put everything in a map. I did some benchmarks for this: Do you think the transducer version can be improved?

Daw-Ran Liou16:09:30

Please let me know if you have any thought: @U09LZR36F @U8MJBRSR5 . Thanks!


Looks about the same performance?


Seems like non xf version is better in that case.

Vincent Cantin08:09:03

that was not the end of the story, go to see the github issue ..

Daw-Ran Liou17:09:27

Sorry for the confusion, @U09LZR36F . The xf version is faster than non-xf version now. I should've update the user ns.