Dict comparison slower on JS target #3822
Replies: 2 comments
-
I'm surprised the gap isn't bigger! One is implemented in C and the other in JavaScript. Did you have some idea for improving performance of the JavaScript one? |
Beta Was this translation helpful? Give feedback.
-
I haven't yet looked into the Re. the equality check, there's a win to be had by returning as soon as any entry fails the equality check, which is implemented in gleam-lang/stdlib#738. Doesn't help in the test case above which compares identical dicts though, performance only improves when comparing dicts of the same size that aren't equal. |
Beta Was this translation helpful? Give feedback.
-
While doing some benchmarking I found that comparing two identical
Dict
s can be 10-12x slower than Erlang.Profiling showed the time is 60-70% in the iteration over the dict's contents. Does anyone know what the expected tradeoffs are of the
Dict
implementation on JS (it seems to be a custom HashMap implementation, indict.mjs
), or are performance differences between the two targets unavoidable here?I also tested a native
Map<number, number>
in JS but it was still 4x slower than Erlang. Perhaps Erlang's maps are just faster, or it may be due to the value equality check needing to be implemented manually in JS, whereas on Erlang it's provided by the VM.Here's some code which Erlang runs in 0.45 seconds, and JavaScript in 5.2 seconds. It compares two identical 10,000 entry dicts:
Beta Was this translation helpful? Give feedback.
All reactions