3 ms·
Basically, anything that isn't a thin pointer (*T, chan, map) gets boxed nowadays. The end result is that both words of an interface value are always pointers [
by kbolino 2y ago
Basically, anything that isn't a thin pointer (*T, chan, map) gets boxed nowadays. The end result is that both words of an interface value are always pointers [1], which is very friendly to the garbage collector (setting aside the extra allocations when escape analysis fails). I've seen some tricks in the standard library to avoid boxing, e.g. how strings and times are handled by log/slog [2].
[1]: https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#overview-of-the-datastructures https://github.com/teh-cmc/go-internals/blob/master/chapter2...
[2]: https://cs.opensource.google/go/go/+/refs/tags/go1.24.1:src/log/slog/value.go;l=21 https://cs.opensource.google/go/go/+/refs/tags/go1.24.1:src/...
- deleted 2y ago[deleted]
- ncruces 2y agoslog.Value looks incredibly useful. Just imagine a day where database/sql doesn't generate a tonne of garbage because it moves to use something like that?