3 ms·
Go in effect does pre-allocs in that it does variable liveness analysis and any variables that are allocated within a function but who's address isn't assigned
by tankenmate 9y ago
Go in effect does pre-allocs in that it does variable liveness analysis and any variables that are allocated within a function but who's address isn't assigned to another variable that is from outside the function or returned from the function is allocated on the stack. This means it is automatically freed when the function returns (or stack frame is unwound). This also means that you can be certain that any state changes are from within the current function or any of its children if passed to a child.
- weberc2 9y agoYeah, I know this optimization as escape analysis, but it's pretty easily defeated IIRC. I don't think it even applies across compilation units. In some ways, it's nice that the escape analysis is naive--it makes it easy to reason about and it behaves somewhat intuitively; however, in other cases it means unnecessary allocations.