scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

s.c.i.IntMap and s.c.m.LongMap do lot of allocations during traversing by foreach/foreachKey/iterator #11084

Open plokhotnyuk opened 6 years ago

plokhotnyuk commented 6 years ago

Traversing of map with 128 key/value pairs can produce from 1.5K to 5K bytes for GC on JDK 8/11, while on GraalVM EE almost zero allocation is produced.

Ichoran commented 6 years ago

I'm not sure this is exactly a bug, but rather an effect of how boxing works. LongMap stores its Long keys unboxed; the foreach etc. methods are generic and require boxed values. Graal is sufficiently clever to realize that boxing and then usage is unnecessary in many contexts (but sometimes it's unavoidably necessary!).

I'm not sure there's anything to be done here, except note that this is as designed until we have a better specialization story than we do right now. (TASTY may help. Miniboxing could also have helped, but we seem not to be going that way. Regular specialization causes too much bloat.)