3 ms·
I think it's relevant in the sense that it's not particularly impressive once you know the answer. Basically the answer to the title "How the Go runtime impleme
by simias 8y ago
I think it's relevant in the sense that it's not particularly impressive once you know the answer. Basically the answer to the title "How the Go runtime implements maps efficiently (without generics)" is "by using compiler magic".
Furthermore the article presents Go's approach superior to C++ because of the reduced code generation (since it uses a "maptype" struct for the type-specific information) but doesn't talk about the drawback of such an approach: you have additional indirections in the mapping code and the compiler can't inline and optimize for specific types. Of course in some cases that's actually desirable, very large code size can be problematic.
I could also add that you could pretty easily implement Go-style hashes in C++ (actually that's often how you implement generic hashes in C, using helper functions depending on the type) but you can't implement C++-style hashes in Go without hacking the compiler or using codegen.