3 ms·
> I would have assumed that the Golang compiler would just statically determine the set of vtables that need to be used by the program and write them up front i
by cwzwarich 11y ago
> I would have assumed that the Golang compiler would just statically determine the set of vtables that need to be used by the program and write them up front into rodata. Am I missing something?
IIRC the Go compiler will generate the itables that it can determine are needed at compile time, but because you can dynamically request an interface conformance for a type there is also a runtime fallback.
Swift does something similar; the compiler tries to generate protocol conformances as much as possible, but because there may be an unbounded number of types at runtime, clearly it can't generate all of them.
- pcwalton 11y ago> IIRC the Go compiler will generate the itables that it can determine are needed at compile time, but because you can dynamically request an interface conformance for a type there is also a runtime fallback. That would make more sense. But http://research.swtch.com/interfaces http://research.swtch.com/interfaces claims it's all runtime-based (though that document may well be out of date).
- cwzwarich 11y agoIt looks like the optimization I remember was implemented in gccgo, but maybe they never added it to the main compiler: http://www.airs.com/blog/archives/277 http://www.airs.com/blog/archives/277