• Dave Cheney's avatar
    cmd/compile/internal/gc: avoid append when building Type fields · 1a9373bc
    Dave Cheney authored
    As a followup to CL 21296, avoid append operations when constructing the
    fields of a Type if the length is known beforehand
    
    This also includes some small scoping driveby cleanups, and a change to
    tointerface0 to avoid iterating over the field list twice.
    
    compilebench shows a very small reduction in allocations.
    
     name      old time/op    new time/op    delta
    Template     364ms ± 5%     363ms ± 4%    ~     (p=0.945 n=20+19)
    Unicode      182ms ±11%     185ms ±12%    ~     (p=0.445 n=20+20)
    GoTypes      1.14s ± 2%     1.14s ± 3%    ~     (p=0.221 n=20+20)
    Compiler     5.85s ± 2%     5.84s ± 2%    ~     (p=0.369 n=20+20)
    
    name      old alloc/op   new alloc/op   delta
    Template    56.7MB ± 0%    56.7MB ± 0%  -0.04%  (p=0.000 n=20+20)
    Unicode     38.3MB ± 0%    38.3MB ± 0%    ~     (p=0.728 n=20+19)
    GoTypes      180MB ± 0%     180MB ± 0%  -0.02%  (p=0.000 n=20+20)
    Compiler     812MB ± 0%     812MB ± 0%  -0.02%  (p=0.000 n=19+20)
    
    name      old allocs/op  new allocs/op  delta
    Template      482k ± 0%      480k ± 0%  -0.34%  (p=0.000 n=20+20)
    Unicode       377k ± 0%      377k ± 0%  -0.04%  (p=0.010 n=20+20)
    GoTypes      1.36M ± 0%     1.35M ± 0%  -0.24%  (p=0.000 n=20+20)
    Compiler     5.47M ± 0%     5.46M ± 0%  -0.11%  (p=0.000 n=20+18)
    
    Change-Id: Ibb4c40229fa3816acd8de98ba41d1571a2aabacf
    Reviewed-on: https://go-review.googlesource.com/21352Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Dave Cheney <dave@cheney.net>
    1a9373bc
dcl.go 28.8 KB