• Quentin Renard's avatar
    net/http: improve performance for parsePostForm · 59320c39
    Quentin Renard authored
    Remove the use of io.ReadAll in http.parsePostForm to avoid converting
    the whole input from []byte to string and not performing well
    space-allocated-wise.
    
    Instead a new function called parsePostFormURLEncoded is used and is
    fed directly an io.Reader that is parsed using a bufio.Reader.
    
    Benchmark:
    
    name         old time/op    new time/op    delta
    PostQuery-4    2.90µs ± 6%    2.82µs ± 4%     ~       (p=0.094 n=9+9)
    
    name         old alloc/op   new alloc/op   delta
    PostQuery-4    1.05kB ± 0%    0.90kB ± 0%  -14.49%  (p=0.000 n=10+10)
    
    name         old allocs/op  new allocs/op  delta
    PostQuery-4      6.00 ± 0%      7.00 ± 0%  +16.67%  (p=0.000 n=10+10)
    
    Fixes #14655
    
    Change-Id: I112c263d4221d959ed6153cfe88bc57a2aa8ea73
    Reviewed-on: https://go-review.googlesource.com/20301Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    59320c39
request.go 38.2 KB