]> Cypherpunks repositories - gostls13.git/commit
encoding/json: inline fieldByIndex
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 22 Jul 2018 11:36:15 +0000 (12:36 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 22 Aug 2018 15:55:40 +0000 (15:55 +0000)
commit75e7e05aee4c0588a11f79bb5c46290ca753bf20
tree8fc62677876ceb33615ce253ced65fca79277bcf
parent8148726676d63c2aebc561717a949135389868b8
encoding/json: inline fieldByIndex

This function was only used in a single place - in the field encoding
loop within the struct encoder.

Inlining the function call manually lets us get rid of the call
overhead. But most importantly, it lets us simplify the logic afterward.
We no longer need to use reflect.Value{} and !fv.IsValid(), as we can
skip the field immediately.

The two factors combined (mostly just the latter) give a moderate speed
improvement to this hot loop.

name           old time/op    new time/op    delta
CodeEncoder-4    6.01ms ± 1%    5.91ms ± 1%  -1.66%  (p=0.002 n=6+6)

name           old speed      new speed      delta
CodeEncoder-4   323MB/s ± 1%   328MB/s ± 1%  +1.69%  (p=0.002 n=6+6)

Updates #5683.

Change-Id: I12757c325a68abb2856026cf719c122612a1f38e
Reviewed-on: https://go-review.googlesource.com/125417
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/encoding/json/encode.go