Skip to content

Instantly share code, notes, and snippets.

@maciej
Last active July 25, 2017 10:25
Show Gist options
  • Save maciej/18bee77cf53c530e376f472ba1a20f7c to your computer and use it in GitHub Desktop.
Save maciej/18bee77cf53c530e376f472ba1a20f7c to your computer and use it in GitHub Desktop.
HPPC LongIntMap memory usage
name := "map-sizes"
version := "1.0"
scalaVersion := "2.12.2"
libraryDependencies += "com.carrotsearch" % "hppc" % "0.7.2"

After a single run of RandomMapGenerator the reported retained size by the Map is ~1.6GiB. YourKit profiler was used.

import com.carrotsearch.hppc.LongIntHashMap
import scala.util.Random
object RandomMapGenerator {
private[this] val random = new Random()
private val ElementsToGenerate = 100 * 1000 * 1000
def main(args: Array[String]): Unit = {
val map = new LongIntHashMap()
for (i <- 0 until ElementsToGenerate) {
val key = random.nextLong()
val value = random.nextInt()
map.put(key, value)
}
println(s"Map generated, feel free to dump the heap. Key distribution is: ${map.visualizeKeyDistribution(8)}.")
// Wait
Console.in.readLine()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment