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
Currently the library internally uses AppendRaw with safeASCII set to true for scenarios where it is sure that the text is correct, but for all external user types, the library forces ascii escaping.
That escape check is very expensive for large objects. E.g. for an 8MB hex string (where my type knows that it generated correct ASCII), the default encoder through MarshalText appends it to the buffer in 5.5ms, whereas setting safeASCII to true (hacking the lib) will cause the data to be appended to the buffer in 0.8ms. That's almost a whole order of magnitude lost time on uselessly iterating the string.
I'm not entirely sure what the solution could be, maybe a RawMessage type that does not get escaped? Or some way for a V2 marshaller to signal that the output is "final"?
The text was updated successfully, but these errors were encountered:
This is somewhat related to golang/go#33422. At present, the module errs on the side of correctness, which means that it always checks for validity according to the JSON grammar even if the caller knows for certain that the input is valid. I think this is still the right default, but an API that opts into looser guarantees seems plausible.
Currently the library internally uses
AppendRaw
withsafeASCII
set totrue
for scenarios where it is sure that the text is correct, but for all external user types, the library forces ascii escaping.That escape check is very expensive for large objects. E.g. for an 8MB hex string (where my type knows that it generated correct ASCII), the default encoder through MarshalText appends it to the buffer in 5.5ms, whereas setting
safeASCII
totrue
(hacking the lib) will cause the data to be appended to the buffer in 0.8ms. That's almost a whole order of magnitude lost time on uselessly iterating the string.I'm not entirely sure what the solution could be, maybe a RawMessage type that does not get escaped? Or some way for a V2 marshaller to signal that the output is "final"?
The text was updated successfully, but these errors were encountered: