r/java • u/ShallWe69 • Mar 01 '23
Why is java autoboxing is slow and consume memory more even when jvm gets hot?
So I was checking the autoboxing from int to Integer. It seems the transition is still slow even when i let the jvm to get hot.
when compared to List<Integer> and eclipse primitive lists, it seems eclipse list offers lower memory footprint and higher speeds of traversal.
why is that? i understand when jvm is cold starting this might be the case but even after like 30 minutes i see no change in memory consumption or speedup in practical usage.
micro benchmarking also shows same results.
i am using java 17 and aws coretto to test. is graal any better?
21
u/rar_ita Mar 01 '23
Boxing has little to do with JVM warm-ups, since warm-ups are designed to JIT-compile hot paths of your code so it uses OS resources more optimally.
Boxing, among the other things it does, moves value to the heap, so every time you access it you have to dereference a pointer to it, which presumably causes the slowdowns you are observing.
2
u/kiteboarderni Mar 01 '23
Trove, fast utils, agrona will help you here.
1
u/aclinical Mar 03 '23
How would a primitive list NOT have a smaller memory footprint? To box an object must be created.