3 ms·
The work is already underway in Project Valhalla: http://openjdk.java.net/projects/valhalla/ http://openjdk.java.net/projects/valhalla/ Once it's been decided
by pron 12y ago
The work is already underway in Project Valhalla: http://openjdk.java.net/projects/valhalla/ http://openjdk.java.net/projects/valhalla/
Once it's been decided Java should get value types, generic reification became a more urgent necessity.
- alkonaut 12y agoInteresting. Curious to see if they choose exactly the same approach to e.g. value types as the CLR and C# teams did. In C# it feels like there are very few places where choices could have been made differently. Something I really miss in C#/Java is a possibility to opt out of GC and use more stack allocation.
- pron 12y agoJava's value types will be immutable, while in C# I believe structs are mutable. This is a very important difference with serious implications to concurrency. > Something I really miss in C#/Java is a possibility to opt out of GC and use more stack allocation. The tradeoffs are often not what you think they are.
- alkonaut 12y agoMutable structs in c# are rare, rarely useful and often dangerous, but in some perf critical scenarios that hack is needed. Most notably the standard List<T>.Enumerator is a mutable struct because othrrwise an object would have to be created on the heap for the sole purpose of iterating a list. Not sure whether this was actually one of the reasons for allowing mutable structs to begin with, the use case is critical enough that it might well have been.
- moomin 12y agoYou can in C#. You can also do tricks like allocating large struct arrays for stuff that 100% isn't going to need to be garbage collected.
- alkonaut 12y agoYes and you do things in Java like create an MyIntCollection to get around the shortcomings of generics wrt. primitives, but the point is that it is just that: workarounds. What I really want is for perf to be good while the code is still clean/readable/expressive/idiomatic. In Java/C# you must usually write idiomatic+slow and then refactor into fast kludges.
- ygra 12y agoI'd say that's always the case. Performance for the vast majority of code is good enough with idiomatic or even horrible code. Places where you need to work against the language for perf reasons should be rare (and if it concerns most of the code in a project, then I'd question the choice of language for that project). Also that holds true for most languages. Even in C you'll avoid allocations in tight loops that need to be fast because it comes with an unpredictable performance cost. That's not much different than pre-allocating a buffer to work on prior to an algorithm in C#.
- alkonaut 12y agoAgree it's always the case regardless of language, but it's about moving that boundary where you have to leave idiomatic and make something less readable in order for it to perform. As an example, C#'s value types and generics with primitives makes that a lot better than in java.