3 ms·
Scala runs on the JVM and uses boxing, but unreliably attempts unboxing. Sometimes. Maybe. Meanwhile, in Haskell, there already are value types and newtype wra
by coolsunglasses 12y ago
Scala runs on the JVM and uses boxing, but unreliably attempts unboxing. Sometimes. Maybe.
Meanwhile, in Haskell, there already are value types and newtype wrappers are erased at compile-time, eliminating all overhead.
- bad_user 12y agoNo, that's not true. Scala does true specialization of primitives by means of the @specialized annotation: http://www.scala-lang.org/api/2.10.3/index.html#scala.specialized http://www.scala-lang.org/api/2.10.3/index.html#scala.specia... This functionality is old and because it tends to generate many class files, there's also a newer project that fixes that and that should replace the @specialized annotation soon: http://scala-miniboxing.org/ http://scala-miniboxing.org/ But wait, there's more - Scala 2.10 also brought with it "value classes", as in zero-overhead wrappers: http://docs.scala-lang.org/overviews/core/value-classes.html http://docs.scala-lang.org/overviews/core/value-classes.html Speaking of the JVM and overhead, the JVM also does escape analysis and it can choose to allocate values on the stack in case they don't escape their context: http://docs.oracle.com/javase/7/docs/technotes/guides/vm/performance-enhancements-7.html#escapeAnalysis http://docs.oracle.com/javase/7/docs/technotes/guides/vm/per...
- sanxiyn 12y ago"The Java Hotspot Server Compiler implements the flow-insensitive escape analysis algorithm." This is actually a big problem. The key word is "flow-insensitive". Because current JVM escape analysis is flow-insensitive, it misses lots of opportunities. Thankfully, this is changing. Oracle recently published "Partial Escape Analysis" paper http://dl.acm.org/citation.cfm?id=2544157 http://dl.acm.org/citation.cfm?id=2544157 and I hope it will be integrated in future versions of JVM.
- pjmlp 12y agoThis is great! Thanks for pointint it out. I follow Graal since the Maxime days and am looking forward to the day it might replace Hotspot, specially if Truffle comes along. What might already happen in Java 9, given the Graal/HSAIL ongoing work.