You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the Map.apply methods for the immutable data structures (and getOrElse) are internally creating Somes which are thrown away.
Profiling shows that this creates a non-negligible cost.
Implementation specific overrides of apply() and getOrElse() would remove the performance penalty, whilst introducing no changes to the semantics of these core classes.
This may result in some (trivial) code duplication in the implementations.
objectSomethingextendsApp {
println("hello world")
valstrings=Array("foo", "bar", "baz", "quux")
defget(i: Int):String= {
if (i <1000000000) strings(i&3)
elsethrownewException("Too big")
}
varsum:Long=0
(1 to 20) foreach {j =>// create a big object to simulate medium-lived active objects on the heapvalbig= (1 to 1000000).toList
(1 to 100000000) foreach { i =>
sum += get(i).length
}
// just to keep the ref alive
require(big.nonEmpty)
}
valuptime= java.lang.management.ManagementFactory.getRuntimeMXBean().getUptime()
println("goodbye world, I took "+ uptime)
}
takes about 5 - 6 seconds as above, and 6 - 7 seconds when the "strings(i&3)" is converted to "Some(strings(i&3)).get", mimicking the Map.apply behaviour.
as per the discussion on google groups: https://groups.google.com/d/msg/scala-user/WV-3xN8eRQE/cpTHqlie-B4J
the Map.apply methods for the immutable data structures (and getOrElse) are internally creating Somes which are thrown away.
Profiling shows that this creates a non-negligible cost.
Implementation specific overrides of apply() and getOrElse() would remove the performance penalty, whilst introducing no changes to the semantics of these core classes.
This may result in some (trivial) code duplication in the implementations.
Related to #4469
takes about 5 - 6 seconds as above, and 6 - 7 seconds when the "strings(i&3)" is converted to "Some(strings(i&3)).get", mimicking the Map.apply behaviour.
Further analysis available in the lions-share sbt plugin example: https://github.com/fommil/lions-share/
The text was updated successfully, but these errors were encountered: