6 ms·
> but it puts a lot more pressure on the GC than simple local stack variables. Do you have evidence for this claim? AFAIK the Go compiler does escape analysis,
by dist1ll 4y ago
> but it puts a lot more pressure on the GC than simple local stack variables.
Do you have evidence for this claim? AFAIK the Go compiler does escape analysis, and allocates pointers that don't escape on the stack.
- throwaway894345 4y agoThis is true, but it's hard to tell if a pointer escapes or not without actually profiling. That said, I don't think the answer is to avoid pointers, but rather to get comfortable with profiling the escape analyzer. By default, I just stick to the subset of Go which I know won't escape--functions can take pointer parameters, but I'm very careful about returning pointers to data that would otherwise be stack-allocated (even though it's not especially idiomatic, I'll often prefer mutating an `out T` parameter rather than returning a `T` because I know the former will not allocate).