Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: generate static calls when callee is known #18270
It would be nice if the compiler optimized dynamic function calls into static ones when the callee is known. This would save ~2ns/call for calls to functions with no free variables, and ~3ns/call for functions that need a closure.
changed the title
cmd/compile: opt: generate static calls when callee is known
Dec 10, 2016
As of CL 65071 the compiler can inline f inside B
The more general problem of turning dynamic calls into static ones is still open though and will probably require some sort of copy propagation for function values. I'd like to take a stab at it at some point.
All of A, B, C now generate basically identical code.
A gets inlined into BenchmarkA, whereas B and C do not get inlined into BenchmarkB and BenchmarkC, respectively (I think we don't inline functions with closures in them). That makes BenchmarkA a bit faster, but that's not really what this issue is about.
But I'm calling this fixed. We do convert dynamic to static calls. If there are specific instances where this is not happening, we should probably use a new bug.