Go allocation probe

blenderob | 86 points

It is very difficult to avoid putting strings on the heap in go. I used the built in escape analysis tools and made sure I only use a constant amount of memory in the loop in my short https://github.com/fsmv/in.go progress bar program.

The biggest problem is any string you pass as an argument to the fmt functions is moved onto the heap because interface{} is always counted as escaped from the stack (https://github.com/golang/go/issues/8618).

fsmv | 13 hours ago

Hacking into the Go runtime with eBPF is definitely fun.

But for a more long term solution in terms of reliability and overhead, it might be worth raising this as a feature request for the Go runtime itself. Type information could be provided via pprof labels on the allocation profiles.

felixge | 12 hours ago

Interesting... usually you can guess at what is being allocated from the function doing the allocation, but in this case the author was interested in types that are allocated from a ton of locations (spoiler alert: it was strings). Nice use of bpftrace to hack out the information required.

jasonthorsness | 15 hours ago
[deleted]
| 14 hours ago

>> func (thing Thing) String() string { if thing == nil { return nil } str = ... return &str }

It seems like the "..." of str = ... is the interesting part.

osigurdson | 12 hours ago

I forgot to ask, that day that the Go team did an AMA here: did AI have any influence or sway or advice etc in choosing Go over other solutions?

90s_dev | 13 hours ago