Skip to content

mutable.HashMap performance regression in Scala 2.12 #11171

@fwbrasil

Description

@fwbrasil

We're currently migrating from Scala 2.11.11 to 2.12.6 at Twitter and observed a considerable performance regression. One of the factors seems to be more costly mutable hash map lookups. I've copied HashMapBenchmark and compared the results:

Scala 2.11.11

[info] Benchmark                         (size)  (stringsOnly)  (useMissingValues)  Mode  Cnt      Score       Error  Units
[info] HashMapBenchmark.contains             10          false                true  avgt   20    260.206 ±    10.272  ns/op
[info] HashMapBenchmark.contains            100          false                true  avgt   20   2344.312 ±    89.308  ns/op
[info] HashMapBenchmark.contains           1000          false                true  avgt   20  38821.879 ±  2514.815  ns/op
[info] HashMapBenchmark.get                  10          false                true  avgt   20    281.659 ±     4.807  ns/op
[info] HashMapBenchmark.get                 100          false                true  avgt   20   2541.033 ±    28.172  ns/op
[info] HashMapBenchmark.get                1000          false                true  avgt   20  50316.082 ± 22211.830  ns/op
[info] HashMapBenchmark.getOrElse            10          false                true  avgt   20    346.650 ±     5.772  ns/op
[info] HashMapBenchmark.getOrElse           100          false                true  avgt   20   3307.532 ±   214.753  ns/op
[info] HashMapBenchmark.getOrElse          1000          false                true  avgt   20  47350.125 ±  1592.833  ns/op
[info] HashMapBenchmark.getOrElseUpdate      10          false                true  avgt   20    305.341 ±     6.406  ns/op
[info] HashMapBenchmark.getOrElseUpdate     100          false                true  avgt   20   3138.793 ±   160.772  ns/op
[info] HashMapBenchmark.getOrElseUpdate    1000          false                true  avgt   20  54917.471 ±  6087.586  ns/op

Scala 2.12.6

[info] Benchmark                         (size)  (stringsOnly)  (useMissingValues)  Mode  Cnt      Score      Error  Units
[info] HashMapBenchmark.contains             10          false                true  avgt   20    321.063 ±    9.857  ns/op
[info] HashMapBenchmark.contains            100          false                true  avgt   20   3505.131 ±  245.030  ns/op
[info] HashMapBenchmark.contains           1000          false                true  avgt   20  49901.758 ± 2116.674  ns/op
[info] HashMapBenchmark.get                  10          false                true  avgt   20    341.963 ±   10.851  ns/op
[info] HashMapBenchmark.get                 100          false                true  avgt   20   4004.163 ±  192.809  ns/op
[info] HashMapBenchmark.get                1000          false                true  avgt   20  56306.171 ± 2128.746  ns/op
[info] HashMapBenchmark.getOrElse            10          false                true  avgt   20    442.490 ±    9.025  ns/op
[info] HashMapBenchmark.getOrElse           100          false                true  avgt   20   5111.343 ±   28.240  ns/op
[info] HashMapBenchmark.getOrElse          1000          false                true  avgt   20  67521.642 ± 1711.990  ns/op
[info] HashMapBenchmark.getOrElseUpdate      10          false                true  avgt   20    381.666 ±   26.239  ns/op
[info] HashMapBenchmark.getOrElseUpdate     100          false                true  avgt   20   4395.782 ±   36.841  ns/op
[info] HashMapBenchmark.getOrElseUpdate    1000          false                true  avgt   20  60440.328 ± 1636.287  ns/op

To reproduce:

git clone git@github.com:fwbrasil/scala-graal.git
cd scala-graal
sbt "+jmh:run -w 1 -r 1 MutableHashMapBenchmark"

Note: the project is called scala-graal because I've been using it to test graal changes, but the jmh benchmark runs on C2 by default.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions