]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/x86: estimate text size
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 14 Mar 2016 19:49:58 +0000 (12:49 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 16 Mar 2016 23:27:19 +0000 (23:27 +0000)
We can’t perfectly predict how large the function
will be, but we can make a safe overestimate.
No significant CPU time changes.

name       old alloc/op    new alloc/op    delta
Template      67.7MB ± 0%     67.5MB ± 0%   -0.24%          (p=0.029 n=4+4)
Unicode       43.9MB ± 0%     43.8MB ± 0%   -0.13%          (p=0.029 n=4+4)
GoTypes        244MB ± 0%      244MB ± 0%   -0.28%          (p=0.029 n=4+4)
Compiler      1.05GB ± 0%     1.05GB ± 0%   -0.38%          (p=0.029 n=4+4)

name       old allocs/op   new allocs/op   delta
Template        795k ± 0%       794k ± 0%   -0.14%          (p=0.029 n=4+4)
Unicode         569k ± 0%       569k ± 0%     ~             (p=0.114 n=4+4)
GoTypes        2.59M ± 0%      2.58M ± 0%   -0.11%          (p=0.029 n=4+4)
Compiler       11.0M ± 0%      11.0M ± 0%   -0.09%          (p=0.029 n=4+4)

Passes toolstash -cmp.

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

src/cmd/internal/obj/data.go
src/cmd/internal/obj/x86/asm6.go

index 0bb8aa2a7eff294a4147199af8b8d6644fb540e4..a3cc178adca53690b6d67e7c70b78782f6d1b277 100644 (file)
@@ -53,6 +53,20 @@ func (s *LSym) Grow(lsiz int64) {
        s.P = s.P[:siz]
 }
 
+// GrowCap increases the capacity of s.P to c.
+func (s *LSym) GrowCap(c int64) {
+       if int64(cap(s.P)) >= c {
+               return
+       }
+       if s.P == nil {
+               s.P = make([]byte, 0, c)
+               return
+       }
+       b := make([]byte, len(s.P), c)
+       copy(b, s.P)
+       s.P = b
+}
+
 // prepwrite prepares to write data of size siz into s at offset off.
 func (s *LSym) prepwrite(ctxt *Link, off int64, siz int) {
        if off < 0 || siz < 0 || off >= 1<<30 {
index 9f2a32724fbc8c861e6edc9aa331acf19b73664b..ec0b0a130b87c12d18cf3478d5f85f1edb2eb689 100644 (file)
@@ -1796,7 +1796,9 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
        }
 
        var q *obj.Prog
+       var count int64 // rough count of number of instructions
        for p := s.Text; p != nil; p = p.Link {
+               count++
                p.Back = 2 // use short branches first time through
                q = p.Pcond
                if q != nil && (q.Back&2 != 0) {
@@ -1821,6 +1823,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
                        }
                }
        }
+       s.GrowCap(count * 5) // preallocate roughly 5 bytes per instruction
 
        n := 0
        var c int32