4 ms·
> Supporting generics over primitives and values, through specialization, is the topic of a separate investigation. Sort of off-topic, but isn't that dilemma a
by hencq 12y ago
> Supporting generics over primitives and values, through specialization, is the topic of a separate investigation.
Sort of off-topic, but isn't that dilemma also the one preventing Go from having generics?
- fiatmoney 12y agoBasically. If you want to implement generics you basically have the choice of 1) boxing (Java approach), 2) instantiating a different type for each generic parameter (C++ approach), and 3) doing something in the runtime to enable a relatively transparent hybrid (C# approach). They each have their own tradeoffs in terms of flexibility, memory consumption, runtime complexity, and compilation / linking time.
- acjohnson55 12y agoHow does Scala's approach fit with these options?
- coolsunglasses 12y agoScala 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.