• Daniel Martí's avatar
    encoding/json: defer error context work until necessary · 9a2a34e1
    Daniel Martí authored
    Calling Name on a reflect.Type is somewhat expensive, as it involves a
    number of nested calls and string handling.
    
    This cost was showing up when decoding structs, as we were calling it to
    set up an error context.
    
    We can avoid the extra work unless we do encounter an error, which makes
    decoding via struct types faster.
    
    name           old time/op    new time/op    delta
    CodeDecoder-4    31.0ms ± 1%    29.9ms ± 1%  -3.69%  (p=0.002 n=6+6)
    
    name           old speed      new speed      delta
    CodeDecoder-4  62.6MB/s ± 1%  65.0MB/s ± 1%  +3.83%  (p=0.002 n=6+6)
    
    Updates #5683.
    
    Change-Id: I48a3a85ef0ba96f524b7c3e9096cb2c4589e077a
    Reviewed-on: https://go-review.googlesource.com/122467
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    9a2a34e1
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...