You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems the json encoder and decoder has a significant overhead when escaping strings. I've attached a bunch of benchmarks to the end of this report. In short, I have a large string (hex in this case) and I would like to insert it into a json field. My benchmarks just json encode the single hex value.
I would expect the performance to be near the speed of copying the data. However, Go seems to do a lot of extra processing. This report is kind of questioning various parts of that:
I can imagine Go wanting to double check the content of a string, but in that case, it would be nice to have a means to tell the json encoder/decoder that I know the content is valid, just parse it without wasting a ton of time.
I expected the RawMessage to actually not do all kinds of pre-post processing, but alas, Go elegantly ignores that it's "raw", and still does everything.
Annoyingly enough, for types that have MarshalJson implemented, it seems the escaping runs 3 (!!!) times. I haven;t found the 3rd one, but I think two of them are https://github.com/golang/go/blob/master/src/encoding/json/encode.go#L587 and the line right after, where both lines do an appendString call, which internally does the escape checks (yeah, the noescape flag only disables HTML escape checking, not ascii escape checking).
I'm not even entirely sure what's the solution to the various issues.
I'd expect to be able to use the json package without escaping.
I'd expect RawMessage to not be post processed
I'd expect the escaping code to be fast, and not take more time than encoding all the fields
Proposal Details
It seems the json encoder and decoder has a significant overhead when escaping strings. I've attached a bunch of benchmarks to the end of this report. In short, I have a large string (hex in this case) and I would like to insert it into a json field. My benchmarks just json encode the single hex value.
I would expect the performance to be near the speed of copying the data. However, Go seems to do a lot of extra processing. This report is kind of questioning various parts of that:
appendString
call, which internally does the escape checks (yeah, the noescape flag only disables HTML escape checking, not ascii escape checking).I'm not even entirely sure what's the solution to the various issues.
The text was updated successfully, but these errors were encountered: