Go interface values
This repository deep dives Go interface values, what they are, how they work, and when storing a value in a Go interface allocates memory on the heap.
- Labs: a step-by-step walkthrough of the topic
- FAQ: answers to frequently asked questions
- Links: links to related reference material
- Thanks: it takes a community
- Appendix: in-repo reference material
Labs
- Prerequisites: how to get from here to there
- Interface values: whatever you do, do not call it "boxing"
- Escape analysis: to malloc or not to malloc
- Missing mallocs: there's a heap of missing memory
- Lessons learned: key takeaways
FAQ
- What does the
Q
suffix for instructions likeMOVQ
andLEAQ
mean? - What is the x86 assembly instruction
CALL
actually calling? - Where is the
CALL
instruction in ARM assembly? - What is the
hack
directory and the files inside of it?
Q
suffix for instructions like MOVQ
and LEAQ
mean?
What does the Please refer to this answer from the assembly section in the appendix.
CALL
actually calling?
What is the x86 assembly instruction Please refer to this answer from the assembly section in the appendix.
CALL
instruction in ARM assembly?
Where is the Please refer to this answer from the assembly section in the appendix.
hack
directory and the files inside of it?
What is the The hack
directory is a convention I picked up from working on Kubernetes and projects related to Kuberentes. The directory contains scripts useful to the project, but not a core piece of the project itself. For example:
hack/
asm2md.py
: parses the output ofgo tool compile -S -wb=false ./tests/mem/*.go
and produces a markdown tableb2md.py
: parses the output ofgo test -v -count 1 -benchtime 1000x -bench BenchmarkMem -run Mem -benchmem ./tests/mem
and produces a markdown tablegen.py
: generates./tests/mem/bench_test.go
and./tests/mem/types_test.go
Links
- ARM developer documentation
- x86 and amd64 instruction set
- A quick guide to Go assembly
- Go internal application binary interface (ABI) specification
- Logging, interfaces, and allocation
- Go introduction to escape analysise
- Type definitions for leaks
- Enums for escape
- Type definition for a Go stack frame
Thanks
- Many thanks to reddit user nikandfor for their response to my post on this topic. Without that initial work, I am not sure this repository would exist today.
- My gratitude to Crypto Jones from Gopher Slack for keeping me honest about "boxing."
π - My colleague Michael Gasch who spent a lot of time proofreading this repository. Hear that y'all? Any mistakes you find? Totally Michael's fault!
π - Andrew Williams, another co-worker, who did not judge me when he helpfully explained cache lines.
- The first person who offered to help me dig into the assembly, Kevin Grittner!
- Several of my colleagues who directed me to a Trie structure for the repository's bespoke test framework:
- Michal Jankowski
- Zhanghe Liu
- Yiyi Zhou
- Mayank Bhatt
- Arunesh Pandey
Appendix
- Assembly: reference section for go asm