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: optimize data only init struct into writable init data field of the executable file. #15872

Closed
bronze1man opened this issue May 29, 2016 · 1 comment

Comments

@bronze1man
Copy link
Contributor

bronze1man commented May 29, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6 darwin/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH=""
    GORACE=""
    GOROOT="/usr/local/go"
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GO15VENDOREXPERIMENT="1"
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"
  3. What did you do?
    I am writing a program using golang to run in background process in ios,and the ios only give me 5MB memory to run golang code.I reduce almost all memory allocations in my code part,but the golang runtime code part contains a lot memory allocations.
    I found init data in /usr/local/go/src/unicode/tables.go:6944 uses runtime.mallocgc to alloc some heap memory.
    But following code do not alloc heap memory, it put those data into a writable init data field in the executable file,and the data is loaded into memory once by os.I think put the data into writable init data part and do not use them can reduce the memory size pressure in the ios background process(It looks like only count the memory page the has been read once and I do not use unicode),I think skip the runtime.mallocgc process can reduce init time of the program,reduce the pressure of the gc part.(the gc can skip them).
var uncompressDataS = `abcde
// 500KB of binary data.
asdfad
` 
  1. What did you expect to see?
    Init data in /usr/local/go/src/unicode/tables.go:6944 should not use runtime.mallocgc to alloc heap memory. It can put into a writable/readonly init data field in the executable file.
  2. What did you see instead?
    Init data in /usr/local/go/src/unicode/tables.go:6944 uses runtime.mallocgc to alloc some heap memory.

Those heap allocation can be found by GODEBUG=allocfreetrace=1

@randall77
Copy link
Contributor

Those mallocs you see are only for allocating maps. All the slices require no allocations. So this is a duplicate of #2559. I don't see any way to easily fix this, as statically allocated maps would have to be different somehow (at least in their hash function).

One thing I noticed is that growings are happening during the initialization. I've opened a separate bug #15880 for that. It should eliminate a good chunk of the startup allocations you're seeing.

@golang golang locked and limited conversation to collaborators May 29, 2017
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

3 participants