什么';s Go cmd选项';gcflags';所有可能的值
我正在通过内联学习Go内存优化。下面的代码是我的测试代码 我使用什么';s Go cmd选项';gcflags';所有可能的值,go,compiler-optimization,Go,Compiler Optimization,我正在通过内联学习Go内存优化。下面的代码是我的测试代码 我使用go build-gcflags=-m=2 main.go获得所有结果。我跟着你做这件事 我的问题是:“gcflags”的值是什么?文档在哪里,我在谷歌上找不到文档 func fn1() int { s := 1+2 return s } func fn2() string { a := "h" a += "e" a += "l"
go build-gcflags=-m=2 main.go
获得所有结果。我跟着你做这件事
我的问题是:“gcflags”的值是什么?文档在哪里,我在谷歌上找不到文档
func fn1() int {
s := 1+2
return s
}
func fn2() string {
a := "h"
a += "e"
a += "l"
a += "l"
a += "o"
b := " "
c := "w"
c += "o"
c += "r"
c += "l"
c += "d"
d := "d"
d += "e"
d += "e"
d += "e"
d += "e"
d += "e"
d += "e"
d += "e"
d += "e"
d += "e"
s := a + b + c
return s
}
func fn3() {
p := fn1()
s := fn2()
println("p = " + string(p))
println("s = " + s)
}
输出:
go build -gcflags='-m=2' main.go
# command-line-arguments
./main.go:3:6: can inline fn1 as: func() int { s := 1 + 2; return s }
./main.go:16:6: cannot inline fn2: function too complex: cost 81 exceeds budget 80
./main.go:47:6: cannot inline fn3: function too complex: cost 85 exceeds budget 80
我还尝试了-gcflags=-m=3,-gcflags=-m=4,-gcflags=-m=5
,结果如下,很难理解。也许有人能帮我指出方向。
go build -gcflags=-m=3 main.go
# command-line-arguments
./main.go:3:6: can inline fn1 as: func() int { s := 1 + 2; return s }
./main.go:8:6: cannot inline fn2: recursive
./main.go:16:6: can inline fn3 as: func() { p := fn1(); p = fn2(p); println("p = " + string(p)) }
./main.go:17:10: inlining call to fn1 func() int { s := 1 + 2; return s }
./main.go:17:10: Before inlining:
. CALLFUNC l(17) tc(1) int
. . NAME-inlining.fn1 l(3) x(0) class(PFUNC) tc(1) used FUNC-@0
substituting name
. NAME-inlining.s g(2) l(4) x(0) class(PAUTO) tc(1) used int ->
. NAME-inlining.s l(4) x(0) class(PAUTO) tc(1) used int
substituting name
. NAME-inlining.s g(2) l(4) x(0) class(PAUTO) tc(1) used int ->
. NAME-inlining.s l(4) x(0) class(PAUTO) tc(1) used int
substituting name
. NAME-inlining.s g(2) l(4) x(0) class(PAUTO) tc(1) used int ->
. NAME-inlining.s l(4) x(0) class(PAUTO) tc(1) used int
./main.go:17:10: After inlining
. INLCALL-init
. . DCL l(17)
. . . NAME-inlining.~r0 l(3) x(0) class(PAUTO) tc(1) assigned used int
. . AS l(17) tc(1)
. . . NAME-inlining.~r0 l(3) x(0) class(PAUTO) tc(1) assigned used int
. . INLMARK l(+17) x(0)
. INLCALL l(17) tc(1) int
. INLCALL-rlist
. . NAME-inlining.~r0 l(3) x(0) class(PAUTO) tc(1) assigned used int
..... // too much
-gcflags
标志接受标志列表,调用该列表时应将其传递给go tool compile
。因此,您可以在或运行命令中看到所有可能的选项:
go tool compile -help
像你这样的问题最好还是继续问下去。有几个原因:1)这个问题是开放的,不能用一个明确的答案来回答;2) Go核心团队的AFAIK no在SO上查看
[Go]
标记,但其中相当多的标记在邮件列表中处于活动状态。