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 emoji
s:
{: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?Looks about the same performance?
Seems like non xf version is better in that case.
that was not the end of the story, go to see the github issue ..
Sorry for the confusion, @dominicm . The xf version is faster than non-xf version now. I should've update the user ns.
Please let me know if you have any thought: @dominicm @vincent.cantin . Thanks!