Skip to content

Instantly share code, notes, and snippets.

@gustafj gustafj/main.go
Created Nov 29, 2017

Embed
What would you like to do?
Golang 1.9.2 compilation extreme memory usage
package main
import (
"bufio"
"fmt"
"os"
)
var filename = "/tmp/go_compile_test.go"
var numberOfMaps = 10
var sizeOfMap = 1000
func main() {
println("Writing generated output to", filename)
println("Compile using <`go tool -n compile` -memprofile m.prof -goversion go1.9.2 ", filename, ">")
println("Check mem usage using <go tool pprof -top -alloc_space `go tool -n compile` m.prof>")
f, err := os.Create(filename)
if err != nil {
panic(err)
}
w := bufio.NewWriter(f)
_, err = fmt.Fprintln(w, `package main
type stringPair struct {
first string
second string
}
`)
if err != nil {
panic(err)
}
for i := 1; i <= numberOfMaps; i++ {
_, err = fmt.Fprintf(w, "var bigMap%d = map[int]stringPair {\n", i)
if err != nil {
panic(err)
}
for j := 1; j < sizeOfMap; j++ {
_, err = fmt.Fprintf(w, "\t%d: {\"this is the first string for %d\", \"second string for %d\"},\n", j, j, j)
if err != nil {
panic(err)
}
}
_, err = w.WriteString("}\n")
if err != nil {
panic(err)
}
}
w.Flush()
}
@gustafj

This comment has been minimized.

Copy link
Owner Author

gustafj commented Nov 29, 2017

$ go tool pprof -top -alloc_space (go tool -n compile) m.prof | head -20
File: compile
Type: alloc_space
Showing nodes accounting for 1215.06MB, 94.58% of 1284.72MB total
Dropped 125 nodes (cum <= 6.42MB)
      flat  flat%   sum%        cum   cum%
  852.05MB 66.32% 66.32%   852.05MB 66.32%  cmd/compile/internal/ssa.(*regAllocState).computeLive /usr/lib/go/src/cmd/compile/internal/ssa/regalloc.go
   59.02MB  4.59% 70.92%    59.02MB  4.59%  cmd/compile/internal/ssa.(*Func).newValue /usr/lib/go/src/cmd/compile/internal/ssa/func.go
   50.51MB  3.93% 74.85%    50.51MB  3.93%  cmd/compile/internal/gc.(*Progs).Prog /usr/lib/go/src/cmd/compile/internal/gc/gsubr.go
   35.74MB  2.78% 77.63%    35.74MB  2.78%  cmd/compile/internal/ssa.(*Func).setHome /usr/lib/go/src/cmd/compile/internal/ssa/stackalloc.go
      31MB  2.41% 80.04%       31MB  2.41%  cmd/compile/internal/gc.nodl /usr/lib/go/src/cmd/compile/internal/gc/subr.go
   20.21MB  1.57% 81.62%   875.33MB 68.13%  cmd/compile/internal/ssa.(*regAllocState).init /usr/lib/go/src/cmd/compile/internal/ssa/regalloc.go
   15.54MB  1.21% 82.82%    15.54MB  1.21%  cmd/compile/internal/ssa.(*stackAllocState).stackalloc /usr/lib/go/src/cmd/compile/internal/ssa/stackalloc.go
   15.28MB  1.19% 84.01%    15.83MB  1.23%  cmd/compile/internal/ssa.cse /usr/lib/go/src/cmd/compile/internal/ssa/cse.go
   15.26MB  1.19% 85.20%    15.26MB  1.19%  cmd/compile/internal/ssa.storeOrder /usr/lib/go/src/cmd/compile/internal/ssa/schedule.go
   13.17MB  1.03% 86.23%    13.17MB  1.03%  cmd/compile/internal/ssa.schedule /usr/lib/go/src/cmd/compile/internal/ssa/schedule.go
   11.50MB   0.9% 87.12%    11.50MB   0.9%  cmd/compile/internal/gc.newnamel /usr/lib/go/src/cmd/compile/internal/gc/subr.go
    9.10MB  0.71% 87.83%     9.10MB  0.71%  cmd/compile/internal/ssa.(*Func).NewBlock /usr/lib/go/src/cmd/compile/internal/ssa/func.go
    8.72MB  0.68% 88.51%     8.72MB  0.68%  cmd/compile/internal/ssa.(*stackAllocState).buildInterferenceGraph /usr/lib/go/src/cmd/compile/internal/ssa/stackalloc.go
    8.72MB  0.68% 89.19%    20.39MB  1.59%  cmd/compile/internal/ssa.(*stackAllocState).init /usr/lib/go/src/cmd/compile/internal/ssa/stackalloc.go
    8.53MB  0.66% 89.85%     8.53MB  0.66%  cmd/internal/obj/x86.(*AsmBuf).doasm /usr/lib/go/src/cmd/internal/obj/data.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.