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

Proposal: grow buffers more efficiently #679

Open bboreham opened 1 year ago

bboreham commented 1 year ago

json-iterator is using append in many places to grow a buffer, e.g.: https://github.com/json-iterator/go/blob/71ac16282d122fdd1e3a6d3e7f79b79b4cc3b50e/stream.go#L68 https://github.com/json-iterator/go/blob/71ac16282d122fdd1e3a6d3e7f79b79b4cc3b50e/stream_int.go#L29

As noted at https://github.com/golang/go/issues/50774, append is designed to minimize space wasted at the end of the buffer, whereas most people using json-iterator probably want to optimise for minimum CPU usage.

I can make a PR, but posting this as an issue first to get feedback.