diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2020-02-07 11:43:40 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2020-02-07 12:54:58 +0100 |
commit | b20593b3dff4fa1017110c160d6a28ebca6a295f (patch) | |
tree | cce06d128ae1883d9326fc345ccd796328dc312f /erts | |
parent | 446cf84ae7cce870467f4c24aca797a7b9efa425 (diff) | |
download | erlang-b20593b3dff4fa1017110c160d6a28ebca6a295f.tar.gz |
Optimize =:= when comparing maps
Teach `=:=` to immediately return `false` when comparing two maps
of different sizes. That can be much faster for huge maps.
Reported in the elixir forum:
https://elixirforum.com/t/erlang-2-does-not-seem-to-check-map-sizes-before-performing-the-thoroughful-comparison/28910
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/beam/utils.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index d6e069f756..2f7c8dfb5e 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -2973,10 +2973,14 @@ tailrecur_ne: bb = hashmap_val(b) + 1; switch (hdr & _HEADER_MAP_SUBTAG_MASK) { case HAMT_SUBTAG_HEAD_ARRAY: + if (aa[0] != bb[0]) + goto not_equal; aa++; bb++; sz = 16; break; case HAMT_SUBTAG_HEAD_BITMAP: + if (aa[0] != bb[0]) + goto not_equal; aa++; bb++; case HAMT_SUBTAG_NODE_BITMAP: sz = hashmap_bitcount(MAP_HEADER_VAL(hdr)); |