Can most objects in f# be stack allocated #1216
Replies: 3 comments 1 reply
-
just use |
Beta Was this translation helpful? Give feedback.
-
That, for one, would be a breaking change, so it's a no go for us for now. You should allocate on stack explicitly, when you need it. |
Beta Was this translation helpful? Give feedback.
-
As a general rule of thumb: don’t just willy nilly throw everything on the stack. It’s a common misconception that such a thing would always increase speed (true, sometimes it does, but many types are equally fast or faster when living on the heap). Stack is a very limited resource and only small value types should live there. Big stacks can slow down your code, esp in certain async and parallel scenarios. Byref and Span are often more suited for high perf applications and don’t suffer the penalty of an increased stack. |
Beta Was this translation helpful? Give feedback.
-
Objects like
let x = (0,9)
are heap allocated, there're many objects that are toomaybe only allocated in heap when needed, since f# is functional first we can put a lot stuff in stack
Beta Was this translation helpful? Give feedback.
All reactions