code-reviews

2019-09-27T16:54:39.027200Z

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))
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: https://github.com/dawran6/emoji/blob/master/dev/user.clj Do you think the transducer version can be improved?

dominicm 2019-09-28T17:39:51.028Z

Looks about the same performance?

dominicm 2019-09-28T17:40:06.028200Z

Seems like non xf version is better in that case.

2019-09-30T08:58:03.028400Z

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

2019-09-30T17:51:27.028600Z

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

2019-09-27T16:55:30.027400Z

Please let me know if you have any thought: @dominicm @vincent.cantin . Thanks!