3 ms·
I had a friend who was worried about the overhead of interfaces (are methods called by hash lookup on name or by something like a vtbl?), so I compiled a simple
by swolchok 17y ago
I had a friend who was worried about the overhead of interfaces (are methods called by hash lookup on name or by something like a vtbl?), so I compiled a simple example program to test how dynamic dispatch works: http://scott.wolchok.org/vtbl.go http://scott.wolchok.org/vtbl.go
The binary is at http://scott.wolchok.org/6.out http://scott.wolchok.org/6.out . If you search for deadbeef, you'll find a sequence of instructions ending in an indirect jump, so it is decidedly not some kind of string comparison.
The function in the compiler that generates calls through interfaces seems to be cgen_callinter in go/src/{6,8}g/ggen.c, but I can't decipher the terse code therein. Would be interested to learn more about Go method dispatch, especially as regards to dynamic linking -- does Go have it? What if I create a new interface that encompasses objects in a library built before I created that interface? Do I have to rebuild the library?