-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/oauth2/google: very fat binaries produced just by linking it #19523
Comments
This bug is too vague to be actionable, especially since your actual problem wasn't described. The general problem of binary size is already known and tracked. (#6853) If you want to file concrete bugs about packages having init-time dependencies on other packages unnecessarily, feel free. But we don't need another general size bug, so I'm closing this one. Some details on this case, though:
It seems something in the deps of the
But you'll need all those once you do any real work anyway, so this is somewhat of a non-issue. If you want to file a bug about slimming the Closing this one. |
Why the linker is not able to remove all that cruft if I'm only referencing |
Generally because of |
Btw, last year I added the Try:
etc. |
There are no init functions in oauth2/google. Do you mean that the linker is not allowed to remove init functions that are transitively imported? Even if that's true, I fail to see how stuff like grpc gets eventually included without being referenced in any init path I can see.
I will surely open a bug in the oauth2 repo as well, but I wonder if there's something better that the compiler/linker could do.
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
Sent from mobile
… Il giorno 13 mar 2017, alle ore 02:54, Brad Fitzpatrick ***@***.***> ha scritto:
Generally because of init funcs in packages. That is one of the big reasons we push back against unnecessary init-time work. You could file a bug against x/oauth2/google to do more work lazily, as needed, which means the linker would be able to discard more.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
We replied at the same time. The linker's doing almost everything it can do already. Anything more requires a lot of work (to prove to itself that things are safe and preserve language semantics) for rare gains that are usually only beneficial in somewhat contrived cases like this one. Some init funcs are implicit, like top-level var assignments, dependencies on other packages (and thus to their init funcs), etc. |
It only appears to be 5.5mb on my system
lucky(~/src) % ls -alh size
-rwxrwxr-x 1 dfc dfc 5.5M Mar 13 13:08 size
lucky(~/src) % go version
go version devel +0621092 Mon Mar 13 11:48:03 2017 +1100 linux/amd64
…On Mon, Mar 13, 2017 at 1:08 PM, Brad Fitzpatrick ***@***.***> wrote:
We replied at the same time.
The linker's doing almost everything it can do already. Anything more
requires a lot of work (to prove to itself that things are safe and
preserve language semantics) for rare gains that are usually only
beneficial in somewhat contrived cases like this one.
Some init funcs are implicit, like top-level var assignments, dependencies
on other packages (and thus to their init funcs), etc.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#19523 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcAyzDKz05Zfy3U5AvVvUS9zhliE9gks5rlKUigaJpZM4Maurb>
.
|
It's 9.5 MB on mine. Dave, I think your deps are out of date. |
As one example of the sorts of init-reductions you can do to save space for simple programs like this (but are useless for large programs): This saves 12835 bytes: diff --git a/google/appengine.go b/google/appengine.go
index 4243f4c..74418f9 100644
--- a/google/appengine.go
+++ b/google/appengine.go
@@ -45,7 +45,7 @@ func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSour
// aeTokens helps the fetched tokens to be reused until their expiration.
var (
aeTokensMu sync.Mutex
- aeTokens = make(map[string]*tokenLock) // key is space-separated scopes
+ aeTokens map[string]*tokenLock // key is space-separated scopes
)
type tokenLock struct {
@@ -67,6 +67,9 @@ func (ts *appEngineTokenSource) Token() (*oauth2.Token, error) {
aeTokensMu.Lock()
tok, ok := aeTokens[ts.key]
if !ok {
+ if aeTokens == nil {
+ aeTokens = make(map[string]*tokenLock)
+ }
tok = &tokenLock{}
aeTokens[ts.key] = tok
} I found that using the output above. Then you just keep doing that repeatedly, pruning the dep graph, and then your "Hello, World" program is small again. But your real program is still exactly the same size. |
FWIW, the example is not made up so much. I'm writing a basic oauth2 client, and to be able to login with Google and access the basic profile, I only need For instance, in the case you showed, the toolchain doesn't realize that, since |
If you want to file such a linker bug, feel free. But you should include concrete examples in your bug report of cases it should handle. Filing an |
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
Build this program:
What did you expect to see?
A small binary is produced.
What did you see instead?
A 9Mb binary is produced.
The text was updated successfully, but these errors were encountered: