Commit 37d452c3 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: reduce allocs to c85b77c2 (pre-fmt.go change) levels

Linker and reflect info generation (reflect.go) relies on formatting
of types (tconv). The fmt.Format based approach introduces extra
allocations, which matter in those cases. Resurrected sconv and tconv
code from commit c85b77c2 (fmt.go only); and adjusted it slightly.
The formatter-based approach is still used throughout the rest of the
compiler, but reflect.go now uses the tconv method that simply returns
the desired string.

(The timing data below may not be accurate; I've included it only for
comparison with the numbers in issue #16897).

name       old time/op     new time/op     delta
Template       297ms ± 2%      288ms ± 3%  -3.12%        (p=0.000 n=27+29)
Unicode        155ms ± 5%      150ms ± 5%  -3.26%        (p=0.000 n=30+30)
GoTypes        1.00s ± 3%      0.95s ± 3%  -4.51%        (p=0.000 n=28+29)

name       old alloc/op    new alloc/op    delta
Template      46.8MB ± 0%     46.5MB ± 0%  -0.65%        (p=0.000 n=28+30)
Unicode       37.9MB ± 0%     37.8MB ± 0%  -0.24%        (p=0.000 n=29+30)
GoTypes        144MB ± 0%      143MB ± 0%  -0.68%        (p=0.000 n=30+30)

name       old allocs/op   new allocs/op   delta
Template        469k ± 0%       446k ± 0%  -5.01%        (p=0.000 n=29+30)
Unicode         375k ± 0%       369k ± 0%  -1.62%        (p=0.000 n=30+28)
GoTypes        1.47M ± 0%      1.37M ± 0%  -6.29%        (p=0.000 n=30+30)

The code for sconv/tconv in fmt.go now closely match the code from c85b77c2
again; except that the functions are now methods. Removing the use of
the bytes.Buffer in tconv and special-caseing interface{} has helped a
small amount as well:

name       old time/op     new time/op     delta
Template       299ms ± 3%      288ms ± 3%  -3.83%        (p=0.000 n=29+29)
Unicode        156ms ± 5%      150ms ± 5%  -3.56%        (p=0.000 n=30+30)
GoTypes        960ms ± 2%      954ms ± 3%  -0.58%        (p=0.037 n=26+29)

name       old alloc/op    new alloc/op    delta
Template      46.6MB ± 0%     46.5MB ± 0%  -0.22%        (p=0.000 n=30+30)
Unicode       37.8MB ± 0%     37.8MB ± 0%    ~           (p=0.075 n=30+30)
GoTypes        143MB ± 0%      143MB ± 0%  -0.31%        (p=0.000 n=30+30)

name       old allocs/op   new allocs/op   delta
Template        447k ± 0%       446k ± 0%  -0.28%        (p=0.000 n=30+30)
Unicode         369k ± 0%       369k ± 0%  -0.03%        (p=0.032 n=30+28)
GoTypes        1.38M ± 0%      1.37M ± 0%  -0.35%        (p=0.000 n=29+30)

Comparison between c85b77c2 and now (see issue #16897):

name       old time/op     new time/op     delta
Template       307ms ± 4%      288ms ± 3%  -6.24%  (p=0.000 n=29+29)
Unicode        164ms ± 4%      150ms ± 5%  -8.20%  (p=0.000 n=30+30)
GoTypes        1.01s ± 3%      0.95s ± 3%  -5.72%  (p=0.000 n=30+29)

name       old alloc/op    new alloc/op    delta
Template      46.8MB ± 0%     46.5MB ± 0%  -0.66%  (p=0.000 n=29+30)
Unicode       37.8MB ± 0%     37.8MB ± 0%  -0.13%  (p=0.000 n=30+30)
GoTypes        143MB ± 0%      143MB ± 0%  -0.11%  (p=0.000 n=30+30)

name       old allocs/op   new allocs/op   delta
Template        444k ± 0%       446k ± 0%  +0.48%  (p=0.000 n=30+30)
Unicode         369k ± 0%       369k ± 0%  +0.09%  (p=0.000 n=30+28)
GoTypes        1.35M ± 0%      1.37M ± 0%  +1.47%  (p=0.000 n=30+30)

There's still a small increase (< 1.5%) for GoTypes but pending a complete
rewrite of fmt.go, this seems ok again.

Fixes #16897.

Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354
Reviewed-on: https://go-review.googlesource.com/29087
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent c345a391
This diff is collapsed.
......@@ -864,7 +864,7 @@ func dcommontype(s *Sym, ot int, t *Type) int {
}
exported := false
p := fmt.Sprintf("%- v", t)
p := t.tconv(FmtLeft | FmtUnsigned)
// If we're writing out type T,
// we are very likely to write out type *T as well.
// Use the string "*T"[1:] for "T", so that the two
......@@ -926,22 +926,22 @@ func dcommontype(s *Sym, ot int, t *Type) int {
}
func typesym(t *Type) *Sym {
return Pkglookup(fmt.Sprintf("%-v", t), typepkg)
return Pkglookup(t.tconv(FmtLeft), typepkg)
}
// tracksym returns the symbol for tracking use of field/method f, assumed
// to be a member of struct/interface type t.
func tracksym(t *Type, f *Field) *Sym {
return Pkglookup(fmt.Sprintf("%-v.%s", t, f.Sym.Name), trackpkg)
return Pkglookup(t.tconv(FmtLeft)+"."+f.Sym.Name, trackpkg)
}
func typelinkLSym(t *Type) *obj.LSym {
name := fmt.Sprintf("go.typelink.%-v", t) // complete, unambiguous type name
name := "go.typelink." + t.tconv(FmtLeft) // complete, unambiguous type name
return obj.Linklookup(Ctxt, name, 0)
}
func typesymprefix(prefix string, t *Type) *Sym {
p := fmt.Sprintf("%s.%-v", prefix, t)
p := prefix + "." + t.tconv(FmtLeft)
s := Pkglookup(p, typepkg)
//print("algsym: %s -> %+S\n", p, s);
......@@ -981,7 +981,7 @@ func itabname(t, itype *Type) *Node {
if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() || !itype.IsInterface() || itype.IsEmptyInterface() {
Fatalf("itabname(%v, %v)", t, itype)
}
s := Pkglookup(fmt.Sprintf("%-v,%-v", t, itype), itabpkg)
s := Pkglookup(t.tconv(FmtLeft)+","+itype.tconv(FmtLeft), itabpkg)
if s.Def == nil {
n := newname(s)
n.Type = Types[TUINT8]
......@@ -1406,7 +1406,7 @@ func dumptypestructs() {
// method functions. None are allocated on heap, so we can use obj.NOPTR.
ggloblsym(i.sym, int32(o), int16(obj.DUPOK|obj.NOPTR))
ilink := Pkglookup(fmt.Sprintf("%-v,%-v", i.t, i.itype), itablinkpkg)
ilink := Pkglookup(i.t.tconv(FmtLeft)+","+i.itype.tconv(FmtLeft), itablinkpkg)
dsymptr(ilink, 0, i.sym, 0)
ggloblsym(ilink, int32(Widthptr), int16(obj.DUPOK|obj.RODATA))
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment