• Brad Fitzpatrick's avatar
    encoding/json: allocate less in NewEncoder · f1583bb9
    Brad Fitzpatrick authored
    The *Encoder is almost always garbage. It doesn't need an
    encodeState inside of it (and its bytes.Buffer), since it's
    only needed locally inside of Encode.
    
    benchmark                 old ns/op    new ns/op    delta
    BenchmarkEncoderEncode         2562         2553   -0.35%
    
    benchmark                 old bytes    new bytes    delta
    BenchmarkEncoderEncode          283          102  -63.96%
    
    R=r
    CC=gobot, golang-dev
    https://golang.org/cl/9365044
    f1583bb9
stream.go 4.72 KB