• Josh Bleecher Snyder's avatar
    cmd/gc: optimize memclr of slices and arrays · f03c9202
    Josh Bleecher Snyder authored
    Recognize loops of the form
    
    for i := range a {
    	a[i] = zero
    }
    
    in which the evaluation of a is free from side effects.
    Replace these loops with calls to memclr.
    This occurs in the stdlib in 18 places.
    
    The motivating example is clearing a byte slice:
    
    benchmark                old ns/op     new ns/op     delta
    BenchmarkGoMemclr5       3.31          3.26          -1.51%
    BenchmarkGoMemclr16      13.7          3.28          -76.06%
    BenchmarkGoMemclr64      50.8          4.14          -91.85%
    BenchmarkGoMemclr256     157           6.02          -96.17%
    
    Update #5373.
    
    Change-Id: I99d3e6f5f268e8c6499b7e661df46403e5eb83e4
    Reviewed-on: https://go-review.googlesource.com/2520Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    f03c9202
issue5373.go 1.39 KB