rorygraves / scalac_perf

The Scala programming language
http://www.scala-lang.org/
16 stars 3 forks source link

mutable set entries should maintain hash #25

Open mkeskells opened 7 years ago

mkeskells commented 7 years ago

HashTables ( e.g. mutable.HashSet) use an Entry that maintains the key and value, but not the hash

this means that the collisions are expensive, and resize is expensive

Investigate the performance that having a hash would provide, using jmh

mkeskells commented 6 years ago

image

ackratos commented 6 years ago

I looked the implementation of LinkedHashSet, createNewEntry doesn't rely on the value:

protected def createNewEntry[B](key: A, dummy: B): Entry = {
    val e = new Entry(key)
    if (firstEntry eq null) firstEntry = e
    else { lastEntry.later = e; e.earlier = lastEntry }
    lastEntry = e
    e
  }

So the maintained hashcode is still key's hashCode. The hotspot shown by jprofiler probably is because numeration operations (like bit shift) in scala cost too long?