• Justin Nuß's avatar
    time: Use AppendFormat in Marshal[Text|JSON] · 5f859ba8
    Justin Nuß authored
    The current implementations of MarshalJSON and MarshalText use
    time.Format which returns a string (converted from a byte slice),
    only to convert it back to a byte slice.
    
    Avoid the conversion (and thus an allocation) by directly appending
    the formatted time to a preallocated byte slice, using the new
    AppendFormat function, introduced in golang.org/cl/1760.
    
    This reduces the allocations done in Marshal[Text|JSON] by 50%.
    
    benchmark                old ns/op     new ns/op     delta
    BenchmarkMarshalJSON     626           507           -19.01%
    BenchmarkMarshalText     598           511           -14.55%
    
    benchmark                old allocs     new allocs     delta
    BenchmarkMarshalJSON     2              1              -50.00%
    BenchmarkMarshalText     2              1              -50.00%
    
    benchmark                old bytes     new bytes     delta
    BenchmarkMarshalJSON     96            48            -50.00%
    BenchmarkMarshalText     96            48            -50.00%
    
    Fixes #11025
    
    Change-Id: I468f78d075a6ecc1cdc839df7fb407fbc6ff2e70
    Reviewed-on: https://go-review.googlesource.com/10555Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    5f859ba8
Name
Last commit
Last update
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...