go-json icon indicating copy to clipboard operation
go-json copied to clipboard

Performance degradation for streamed content when escaped strings or unicode characters present

Open nikolaydimitrov opened this issue 7 months ago • 1 comments

We have found that the performance of json.NewDecoder(in).Decode(&out), i.e. when using streamed decoder is very poor. Compared to json.Unmarshal it is about 80-90x times slower.

Profiling shows that memmove is being called too often and is responsible for 96% of the execution. These two places are the culprit:

  • https://github.com/goccy/go-json/blob/master/internal/decoder/string.go#L152
  • https://github.com/goccy/go-json/blob/master/internal/decoder/string.go#L190

Looking at the code, the problem is that those append (memmove) calls are basically called for every character in the input stream.

nikolaydimitrov avatar May 22 '25 04:05 nikolaydimitrov

We ran into the same problem as this in arrow-go, see https://github.com/apache/arrow-go/issues/448

zeroshade avatar Jul 25 '25 16:07 zeroshade