News for hackers. Stuff that matters.
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by seanmcdirmid on Monday December 18, 2017 @08:45PM (#15957113)
The lack of erasure is a huge usability win (types don’t disappear at run time), as well as a performance win (I’ve been able to do great things with C# generics + value types). I also like the way it naturally deals with static fields (useful for factory routines).
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by pron on Tuesday December 19, 2017 @05:21AM (#15959168)
I think it's a huge loss. Generic type erasure is the main thing that makes simple polyglot interop and code-reuse on the JVM possible. Even things like Python become clunky on .NET because of runtime generics. I gladly give up on the tiny usability gain in exchange for having a rich language ecosystem.

Value types are a different matter, and they are now being added to Java as well. Specialized generics over value types are different from specialized generics for reference types, because they are always invariant.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by throwaway010317 on Tuesday December 19, 2017 @04:17AM (#15958872)
I use C# in my day job and try to learn as much as I can about cool ways to use its type system. Genuinely curious to see some examples if you're able to point me in the right direction?

> I’ve been able to do great things with C# generics + value types

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by naasking on Tuesday December 19, 2017 @10:16AM (#15960736)
You can see a few tricks in my project here: https://github.com/naasking/Dynamics.NET

You can use static classes to cache information about types. That project caches delegates to perform deep copies, to invoke constructors, to check for deep immutability, and whether a type can contain any cycles. This is all done structurally via reflection, but the results are executed only once and cached in static fields by exploiting runtime types.

The cached delegate trick can be used whenever you need to some efficient dynamic dispatching. I use it here [1] in another project to cache the Dapper methods that would be invoked so I can easily compose smaller queries into larger ones that return very complicated objects.

A more complicated example would be the fastest immutable dictionary available for .NET in my Sasa library [2]. Generic methods and types defined on structs are JITted separately, so the dispatching overhead is low. I exploit this to create a very efficient hash array mapped trie.

[1] https://github.com/naasking/Dapper.Compose/blob/master/Dappe...

[2] https://sourceforge.net/p/sasa/code/ci/default/tree/Sasa.Col...