Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Proposal: cmd/compile: add a go:inline directive #21536
Comments
|
This proposal has basically no chance of being accepted. Go eschews knobs. Compiler directives are widely disliked. I don't think it can be implemented reasonably, if at all. Functions are not eligible for inlining for many reasons. These include conceptual implementation difficulty: I have no idea how to inline a function containing defer. And practical implementation difficulty: It took a dedicated person a summer to get non-leaf inlining working correctly, even with part of the implementation already written. And it's still not released because of the binary size and compilation time aspects. Supporting such a directive would mean solving a host of such problems. I personally have long wanted a much smaller directive that causes compilation to fail if a function is deemed ineligible for inlining. This would allow me to refactor without fear that future inlining changes will cause my no-op inlining to become a silent performance regression. Even this much more limited proposal has been rejected forcefully. All that said, if you'd like to work on improving inlining, that'd be fabulous. There are many opportunities to improve inlining decisions, to improve how we do inlining (e.g. partial inlining), and to expand the set of functions that can be unlined. |
|
@josharian The flag |
|
@neelance yes, or alternatively parse the output of |
|
@josharian I already suspected that you want it for the stdlib. May I ask why you didn't build it yet? I get the point of not adding such a feature to the Go compiler itself, but a standalone tool doesn't do any harm if only used by individuals voluntarily. I just cringe when I hear "fear of refactoring". ;-) |
|
@neelance just haven't gotten to it yet; I have little contribution time at the moment and lots I want to do. I'd be delighted if someone else wanted to jump in and do this. The recently introduce runtime function |
mvdan
changed the title from
[proposal] cmd/compile: add a go:inline directive
to
Proposal cmd/compile: add a go:inline directive
Aug 19, 2017
mvdan
changed the title from
Proposal cmd/compile: add a go:inline directive
to
Proposal: cmd/compile: add a go:inline directive
Aug 19, 2017
gopherbot
added this to the Proposal milestone
Aug 19, 2017
gopherbot
added
the
Proposal
label
Aug 19, 2017
gopherbot
commented
Aug 20, 2017
|
Change https://golang.org/cl/57410 mentions this issue: |
|
For the reasons Josh outlined above, we're not going to do this. Note also that even in C/C++, the "inline" directive does not really mean "this must be inlined". It is more a guideline than a rule. |
OneOfOne commentedAug 19, 2017
•
Edited 1 time
-
OneOfOne
Aug 19, 2017
The compiler (gc) has come a long way, however the inliner is sometimes lacking, for example any function with a
for-loopno matter how simple it is, won't get inlined so we either have to use agotoloop instead (which is used few times in the runtime) or just have a one big ugly function.My proposal is to add a
go:inlinedirective that will force inlining, even if it's just for non-exported functions.This will help make a lot of code much cleaner and allows separation of big functions that can't be currently inlined.
If the proposal is accepted, I'd like to work on it.
Another semi-common example:
Related: #17566 #14768
@dr2chase @josharian @randall77 @mvdan