json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.33k stars 1.02k forks source link

Faster ReadString by avoiding memory allocations in []byte to string conversion #678

Closed saurabhagrawal-86 closed 1 year ago

saurabhagrawal-86 commented 1 year ago

Benchstat results:

name                    old time/op    new time/op    delta
_jsoniter_large_file      10.8µs ± 6%     8.9µs ± 7%  -17.69%  (p=0.000 n=10+10)
_jsoniter_large_file-2    10.6µs ±10%     9.2µs ± 5%  -13.07%  (p=0.000 n=10+10)
_jsoniter_large_file-4    10.9µs ±10%     9.2µs ± 9%  -14.91%  (p=0.000 n=10+10)

name                    old alloc/op   new alloc/op   delta
_jsoniter_large_file      4.91kB ± 0%    4.37kB ± 0%  -11.07%  (p=0.000 n=10+10)
_jsoniter_large_file-2    4.91kB ± 0%    4.37kB ± 0%  -11.07%  (p=0.000 n=10+10)
_jsoniter_large_file-4    4.91kB ± 0%    4.37kB ± 0%  -11.07%  (p=0.000 n=10+10)

name                    old allocs/op  new allocs/op  delta
_jsoniter_large_file        78.0 ± 0%       5.0 ± 0%  -93.59%  (p=0.000 n=10+10)
_jsoniter_large_file-2      78.0 ± 0%       5.0 ± 0%  -93.59%  (p=0.000 n=10+10)
_jsoniter_large_file-4      78.0 ± 0%       5.0 ± 0%  -93.59%  (p=0.000 n=10+10)
saurabhagrawal-86 commented 1 year ago

Unsafe is not really safe here.