Skip to content
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

cmd/compile: compress static initialization data? #6993

Closed
gopherbot opened this issue Dec 20, 2013 · 9 comments
Closed

cmd/compile: compress static initialization data? #6993

gopherbot opened this issue Dec 20, 2013 · 9 comments

Comments

@gopherbot
Copy link

by Tyr.Chen:

This code http://play.golang.org/p/e6L16l7i7S will generate 81M executable when doing
"go build". 

$ ls -l
-rwxr-xr-x  1 tchen  522017917  81533376 Dec 20 08:22 test

While changing the code using global variable fixed the issue.
http://play.golang.org/p/pqh9XO_m2J

$ls -l
-rwxr-xr-x  1 tchen  522017917  1534384 Dec 20 08:26 test

See further discussion on
http://stackoverflow.com/questions/20671535/why-this-code-generate-very-big-executable-in-go-around-81m.
@gopherbot
Copy link
Author

Comment 1 by Tyr.Chen:

I'm using osx 10.8.2, go version is 1.1.2.
➜  go  go version
go version go1.1.2 darwin/amd64

@davecheney
Copy link
Contributor

Comment 2:

Also occurs on trunk (so assuming 1.2 as well)

@ality
Copy link
Member

ality commented Dec 20, 2013

Comment 3:

What were you expecting? This seems obvious to me. The compiler
has to store the composite literal data somewhere in the binary.
If you want the zero value, use the zero value:
 func (self *BigData) Clear() {
-   *self = BigData{}
+   var zero BigData
+   *self = zero
 }
Also, you should realize that you're making a bunch of 80MB copies.
#WorkingAsIntended

@minux
Copy link
Member

minux commented Dec 20, 2013

Comment 4:

I think this is bug. I think the compiler should optimize *self = BigData{}
to a simple memclr.

@gopherbot
Copy link
Author

Comment 5 by Tyr.Chen:

Agree that compiler should optimize this use case. I saw bunch of code examples like "x
:= Y{}".

@minux
Copy link
Member

minux commented Dec 20, 2013

Comment 6:

on 2nd thought, the compiler probably should consider some simple data compression
technique here.
for example, *self = BigData{1, 2, 3} should use no more than 3 uint64s.

Labels changed: added release-none, repo-main.

Status changed to LongTerm.

@siritinga
Copy link

Comment 7:

Still present on tip:
go version devel +931cc1aeb3be Wed Jan 22 23:30:52 2014 +0100 linux/arm
In this program: http://play.golang.org/p/EikUFnNvqj a big array (not a slice) of a
struct is created and accessed with range using the index or the value. It seems that if
the struct contains a string (even if not used) AND the struct is accessed using the
value, compilation uses a lot of memory and the program produced is really big or even
fails to compile. 
The program in playground uses about 100 MB of RAM to compile and the binary is 54 MB.
Removing the string (or replacing it by an array of ints, for example) or removing the
second for range loop, will solve the problem.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: compress static initialization data? cmd/compile: compress static initialization data? Jun 8, 2015
@agnivade
Copy link
Contributor

agnivade commented Nov 9, 2017

For reference, the binary is just 4.2MB now with 1.9.2.

@randall77
Copy link
Contributor

Ok, I'm going to close this then.

@golang golang locked and limited conversation to collaborators Nov 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants