]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove most of the Lookupf users and garbage
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 20 Mar 2016 01:17:58 +0000 (18:17 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 21 Mar 2016 07:40:15 +0000 (07:40 +0000)
Introduce garbage-free LookupN to replace most users of Lookupf.

Also, remove the string interning from LookupBytes which was hurting
more than helping.

name       old alloc/op    new alloc/op    delta
Template      63.0MB ± 0%     62.7MB ± 0%  -0.48%         (p=0.000 n=10+9)
Unicode       43.0MB ± 0%     43.0MB ± 0%  -0.17%         (p=0.000 n=10+7)
GoTypes        219MB ± 0%      218MB ± 0%  -0.14%        (p=0.000 n=10+10)
Compiler       992MB ± 0%      991MB ± 0%  -0.12%        (p=0.000 n=10+10)

name       old allocs/op   new allocs/op   delta
Template        683k ± 0%       681k ± 0%  -0.38%         (p=0.000 n=10+8)
Unicode         541k ± 0%       541k ± 0%  -0.11%        (p=0.000 n=10+10)
GoTypes        2.09M ± 0%      2.08M ± 0%  -0.40%        (p=0.000 n=10+10)
Compiler       9.28M ± 0%      9.24M ± 0%  -0.36%        (p=0.000 n=10+10)

Size of $GOROOT/pkg/darwin_amd64 drops from 40124 KB to 40100 KB too,
removing the zero padding as suggested by josharian.

Updates #6853

Change-Id: I3c557266e9325fe29c459cef8e5b8954913e7abb
Reviewed-on: https://go-review.googlesource.com/20931
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/gen.go
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/subr.go

index 0677c3030b1bf9ce92df21dc9607279fccc330a8..a908b3d26816fa2b5f3ae3b869cd867903e62c71 100644 (file)
@@ -529,7 +529,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
        var fld *Node
        var n *Node
        for _, t := range t0.Params().Fields().Slice() {
-               n = newname(Lookupf("a%d", i))
+               n = newname(LookupN("a%d", i))
                i++
                n.Class = PPARAM
                xfunc.Func.Dcl = append(xfunc.Func.Dcl, n)
@@ -548,7 +548,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
        l = nil
        var retargs []*Node
        for _, t := range t0.Results().Fields().Slice() {
-               n = newname(Lookupf("r%d", i))
+               n = newname(LookupN("r", i))
                i++
                n.Class = PPARAMOUT
                xfunc.Func.Dcl = append(xfunc.Func.Dcl, n)
index 45d65b1967e1b5e186847cdbb7e99054505732bd..0107d437b124cea5062b44b472833dcabc56bbd0 100644 (file)
@@ -613,7 +613,7 @@ func funcargs(nt *Node) {
 
                if n.Left == nil {
                        // Name so that escape analysis can track it. ~r stands for 'result'.
-                       n.Left = newname(Lookupf("~r%d", gen))
+                       n.Left = newname(LookupN("~r", gen))
                        gen++
                }
 
@@ -633,7 +633,7 @@ func funcargs(nt *Node) {
 
                        *nn = *n.Left
                        nn.Orig = nn
-                       nn.Sym = Lookupf("~b%d", gen)
+                       nn.Sym = LookupN("~b", gen)
                        gen++
                        n.Left = nn
                }
index 7e192a864a4b99190b53452f11051b2d6de62c6f..72b606e0ab799d32dd1b97cb6c3b9cac86ea01ae 100644 (file)
@@ -594,7 +594,7 @@ func Tempname(nn *Node, t *Type) {
 
        // give each tmp a different name so that there
        // a chance to registerizer them
-       s := Lookupf("autotmp_%.4d", statuniqgen)
+       s := LookupN("autotmp_", statuniqgen)
        statuniqgen++
        n := Nod(ONAME, nil, nil)
        n.Sym = s
index 0424e4727afe3cdc62bf65aee997ccf5fa6df005..345d8eb48023b33bd16f85b2b8dd180d33a1a3f5 100644 (file)
@@ -27,7 +27,7 @@ var renameinit_initgen int
 
 func renameinit() *Sym {
        renameinit_initgen++
-       return Lookupf("init.%d", renameinit_initgen)
+       return LookupN("init.", renameinit_initgen)
 }
 
 // hand-craft the following initialization code
@@ -154,7 +154,7 @@ func fninit(n []*Node) {
        // (9)
        // could check that it is fn of no args/returns
        for i := 1; ; i++ {
-               s := Lookupf("init.%d", i)
+               s := LookupN("init.", i)
                if s.Def == nil {
                        break
                }
index 77cdc195f0a763716d150c07fa5b6bd6ebdfb18d..77e45898a4df16361f31edcdf9b84d2f764743e5 100644 (file)
@@ -851,7 +851,7 @@ func inlvar(var_ *Node) *Node {
 
 // Synthesize a variable to store the inlined function's results in.
 func retvar(t *Field, i int) *Node {
-       n := newname(Lookupf("~r%d", i))
+       n := newname(LookupN("~r", i))
        n.Type = t.Type
        n.Class = PAUTO
        n.Used = true
@@ -863,7 +863,7 @@ func retvar(t *Field, i int) *Node {
 // Synthesize a variable to store the inlined function's arguments
 // when they come from a multiple return call.
 func argvar(t *Type, i int) *Node {
-       n := newname(Lookupf("~arg%d", i))
+       n := newname(LookupN("~arg", i))
        n.Type = t.Type
        n.Class = PAUTO
        n.Used = true
@@ -876,7 +876,7 @@ var newlabel_inl_label int
 
 func newlabel_inl() *Node {
        newlabel_inl_label++
-       n := newname(Lookupf(".inlret%.6d", newlabel_inl_label))
+       n := newname(LookupN(".inlret", newlabel_inl_label))
        n.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
        return n
 }
index 43b692d59d1fa4dad63d05f69c74765b6a9645ac..6be4da8da7b4657ce8ea98350af1c901dc1a8544 100644 (file)
@@ -15,12 +15,12 @@ import (
 
 // "Portable" code generation.
 
-var makefuncdatasym_nsym int32
+var makefuncdatasym_nsym int
 
-func makefuncdatasym(namefmt string, funcdatakind int64) *Sym {
+func makefuncdatasym(nameprefix string, funcdatakind int64) *Sym {
        var nod Node
 
-       sym := Lookupf(namefmt, makefuncdatasym_nsym)
+       sym := LookupN(nameprefix, makefuncdatasym_nsym)
        makefuncdatasym_nsym++
        pnod := newname(sym)
        pnod.Class = PEXTERN
@@ -456,8 +456,8 @@ func compile(fn *Node) {
 
        ginit()
 
-       gcargs := makefuncdatasym("gcargs·%d", obj.FUNCDATA_ArgsPointerMaps)
-       gclocals := makefuncdatasym("gclocals·%d", obj.FUNCDATA_LocalsPointerMaps)
+       gcargs := makefuncdatasym("gcargs·", obj.FUNCDATA_ArgsPointerMaps)
+       gclocals := makefuncdatasym("gclocals·", obj.FUNCDATA_LocalsPointerMaps)
 
        if obj.Fieldtrack_enabled != 0 && len(Curfn.Func.FieldTrack) > 0 {
                trackSyms := make([]*Sym, 0, len(Curfn.Func.FieldTrack))
index 63865177e08a263e48f3debcbfab8925fc4e3a2b..5c8fd0fc3030159793dce46c5f73ec60837aa19e 100644 (file)
@@ -500,7 +500,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
 // data statements for the constant
 // part of the composite literal.
 func staticname(t *Type, ctxt int) *Node {
-       n := newname(Lookupf("statictmp_%.4d", statuniqgen))
+       n := newname(LookupN("statictmp_", statuniqgen))
        statuniqgen++
        if ctxt == 0 {
                n.Name.Readonly = true
index 153e6210ccb209967d84c5f10bd1cdec7d10ea8a..0d197886b0bef0b9b844b3f42d4f9a0a7b364578 100644 (file)
@@ -12,6 +12,7 @@ import (
        "fmt"
        "os"
        "sort"
+       "strconv"
        "strings"
        "unicode"
        "unicode/utf8"
@@ -223,6 +224,15 @@ func LookupBytes(name []byte) *Sym {
        return localpkg.LookupBytes(name)
 }
 
+// LookupN looks up the symbol starting with prefix and ending with
+// the decimal n. If prefix is too long, LookupN panics.
+func LookupN(prefix string, n int) *Sym {
+       var buf [20]byte // plenty long enough for all current users
+       copy(buf[:], prefix)
+       b := strconv.AppendInt(buf[:len(prefix)], int64(n), 10)
+       return LookupBytes(b)
+}
+
 var initSyms []*Sym
 
 var nopkg = &Pkg{