• David Crawshaw's avatar
    reflect: avoid lock for some NumMethod()==0 cases · 3c6ed76d
    David Crawshaw authored
    The encoding/json package uses NumMethod()==0 as a fast check for
    interface satisfaction. In the case when a type has no methods at
    all, we don't need to grab the RWMutex.
    
    Improves JSON decoding benchmark on linux/amd64:
    
    	name           old time/op    new time/op    delta
    	CodeDecoder-8    44.2ms ± 2%    40.6ms ± 1%  -8.11%  (p=0.000 n=10+10)
    
    	name           old speed      new speed      delta
    	CodeDecoder-8  43.9MB/s ± 2%  47.8MB/s ± 1%  +8.82%  (p=0.000 n=10+10)
    
    For #16117
    
    Change-Id: Id717e7fcd2f41b7d51d50c26ac167af45bae3747
    Reviewed-on: https://go-review.googlesource.com/24433Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
    Run-TryBot: David Crawshaw <crawshaw@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    3c6ed76d
type.go 83.8 KB