RFR JDK-7143928 : (coll) Optimize for Empty ArrayList and HashMap

Laurent Bourgès bourges.laurent at gmail.com
Tue Apr 2 07:27:01 UTC 2013

> ---
>  604         Arrays.fill(elementData, newSize, size, null);
> In performance-critical code I would avoid Arrays.fill because it adds a
> bit of overhead (unless it's intrinsified, which I don't think it is).

Last week, I sent few benchmarks I did on array cleaning (zero fill)
comparing Arrays.fill, System.arraycopy, Unsafe.setMemory ...
Arrays.fill is the winner (always faster than arraycopy which use native
code) by 10 - 20% !
I suspect aggressive hotspot optimizations (native code ?) because I agree
Arrays.fill looks like a stupid for-loop !

Does somebody have clues explaining the Arrays.fill performance ?

Is there an alternative way to clear an array giving the best possible
performance (like c memset) ?
it could be useful to have in JDK a native array fill implementation
(System.fill ?) if it gives better performance.


More information about the core-libs-dev mailing list