-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
To reduce GC, C# should provide mechanisms to allocate objects on the stack.
- Escape Analysis. This is the most important thing. We can get "free" performance improvement through it without any code change.
- Syntax to force to allocate on the stack.
(from http://xoofx.com/blog/2015/10/08/stackalloc-for-class-with-roslyn-and-coreclr/)
Escape analysis in many case is impossible to perform. Allocate a class and pass it to a virtual method (for which you know only the type at the callsite, unless allocated in the same method), and you won’t have any way to determine whether stackalloc is safe or not.
So besides escape analysis, we want to have syntax to guarantee some objects allocated on the stack. If the stack-allocated object has finalizer, then its finalizer should be executed once its last reference goes out of scope, not need wait until GC finishes.
wanton7, ygc369, bawNg, itsamelambda, tuespetre and 19 more