• Josh Bleecher Snyder's avatar
    cmd/compile: shrink gc.Type in half · f38f43d0
    Josh Bleecher Snyder authored
    Many of Type's fields are etype-specific.
    This CL organizes them into their own auxiliary types,
    duplicating a few fields as necessary,
    and adds an Extra field to hold them.
    It also sorts the remaining fields for better struct packing.
    It also improves documentation for most fields.
    
    This reduces the size of Type at the cost of some extra allocations.
    There's no CPU impact; memory impact below.
    It also makes the natural structure of Type clearer.
    
    Passes toolstash -cmp on all architectures.
    
    Ideas for future work in this vein:
    
    (1) Width and Align probably only need to be
    stored for Struct and Array types.
    The refactoring to accomplish this would hopefully
    also eliminate TFUNCARGS and TCHANARGS entirely.
    
    (2) Maplineno is sparsely used and could probably better be
    stored in a separate map[*Type]int32, with mapqueue updated
    to store both a Node and a line number.
    
    (3) The Printed field may be removable once the old (non-binary)
    importer/exported has been removed.
    
    (4) StructType's fields field could be changed from *[]*Field to []*Field,
    which would remove a common allocation.
    
    (5) I believe that Type.Nod can be moved to ForwardType. Separate CL.
    
    name       old alloc/op     new alloc/op     delta
    Template       57.9MB ± 0%      55.9MB ± 0%  -3.43%        (p=0.000 n=50+50)
    Unicode        38.3MB ± 0%      37.8MB ± 0%  -1.39%        (p=0.000 n=50+50)
    GoTypes         185MB ± 0%       180MB ± 0%  -2.56%        (p=0.000 n=50+50)
    Compiler        824MB ± 0%       806MB ± 0%  -2.19%        (p=0.000 n=50+50)
    
    name       old allocs/op    new allocs/op    delta
    Template         486k ± 0%        497k ± 0%  +2.25%        (p=0.000 n=50+50)
    Unicode          377k ± 0%        379k ± 0%  +0.55%        (p=0.000 n=50+50)
    GoTypes         1.39M ± 0%       1.42M ± 0%  +1.63%        (p=0.000 n=50+50)
    Compiler        5.52M ± 0%       5.57M ± 0%  +0.84%        (p=0.000 n=47+50)
    
    Change-Id: I828488eeb74902b013d5ae4cf844de0b6c0dfc87
    Reviewed-on: https://go-review.googlesource.com/21611Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    f38f43d0
universe.go 9.85 KB