I think the biggest GC-related performance benefit of value types isn’t that you can allocate them on the stack, since a generational GC will easily eat up those allocations. It’s so that more *long-lived* data can become pointer-free and not scanned at all.
-
-
I don’t know of one. I’ve thought about such optimizations, but it seems hard, because the semantics of value vs. reference types are so different. Plus it would have to be a global optimization, which has problems with separate compilation, etc.
-
This might be a good candidate for a linter that tells you when your class could be a struct instead.
End of conversation
New conversation -
-
-
Although it might not quite be what you're thinking about, PyPy does dynamically, transparently, unbox ints/floats/strings in collection types https://tratt.net/laurie/research/pubs/html/bolz_diekmann_tratt__storage_strategies_for_collections_in_dynamically_typed_languages/ … -- V8 also does something similar for JavaScript.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
The semantic differences between references types and value types mean you can only automatically convert a reference type to a value type if it is deeply immutable, i.e. all its fields are immutable and all its references are to types that are deeply immutable...
-
Some compilers or runtimes, though, can prove some instances of a type don't "escape" and can make a local decision to stack allocate those instances. But that's not a global optimization, and in practice escape analysis tends to be very conservative.
End of conversation
New conversation -
-
-
Both Java and C# will sometimes stack allocate objects if they can prove it's safe. But I don't think they will embed them within other objects.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
.NET Core now does wonders with escape analysis, stack-allocating reference types, and de-virtualization and inlining of their virtual methods.
-
But it happens only in executables built in Release mode, and started without debugger attached. Sometimes it is postponed until PGO kicks in and re-jits methods on hot paths.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.