Created
November 29, 2017 10:29
-
-
Save gustafj/aa3c2e7ba4b3dc2b4701282e73d81646 to your computer and use it in GitHub Desktop.
Golang 1.9.2 compilation extreme memory usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Author
gustafj
commented
Nov 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment