4 ms·
In Go you avoid allocations for small values and use the stack.
by mseepgood 12y ago
In Go you avoid allocations for small values and use the stack.
- deleted 12y ago[deleted]
- Dewie 12y agoDo you do that explicitly or is at a compiler optimization?
- jbooth 12y agoBoth. If you deal with a value type (struct or primitive) and never take the address of it, it can't exist anywhere besides the current stack, value types are copied if you return it out of a function or call another function with it. For reference types, they do have escape analysis, not sure how one would compare it to another language.
- skj 12y agoTo be fair, we do that to avoid GC slowdown issues. If the GC improves to the point where that's no longer an issue, we don't have to do that anymore :)
- eggnet 12y agoA 30% improvement is nice but nowhere near enough to change programming best practices in go. A significant algorithmic change in the GC, like a generational compacting GC or something along those lines, would have to be made to alter go programming strategies.