3 ms·
I've had to use Java for sets and maps of millions of small objects (containing 1-3 integers). The garbage collector choked pretty early after a few (< 20) mill
by jstimpfle 11y ago
I've had to use Java for sets and maps of millions of small objects (containing 1-3 integers). The garbage collector choked pretty early after a few (< 20) millions of them (I think there is no way to hash integers in standard Java without significant object overhead).
Knowing almost nothing about the JVM, what's the best approach to go about this? I considered implementing my own sets / maps on naked int[] / structs of 1-3 naked int[].
- haimez 11y agoObjects are expensive. If you're dealing with millions of them you definitely want to 1.) use primitives where possible (ie: int, not Integer) and 2.) put those primitives in native arrays instead of collections (ie: int[] and not List<Integer>). It sounds like in your use case that means going from the collection of objects pattern to the object of collections pattern.
- QuercusMax 11y agoSounds like you might be looking for something like Trove. http://trove.starlight-systems.com/ http://trove.starlight-systems.com/
- wtetzner 11y agoIt might be useful to try out the Colt collections: https://en.wikipedia.org/wiki/Colt_(libraries) https://en.wikipedia.org/wiki/Colt_(libraries)