Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Somehow expose safeASCII option to outer types? #44

Open
karalabe opened this issue Jun 26, 2024 · 2 comments
Open

Somehow expose safeASCII option to outer types? #44

karalabe opened this issue Jun 26, 2024 · 2 comments

Comments

@karalabe
Copy link

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"?

@dsnet
Copy link
Collaborator

dsnet commented Jun 27, 2024

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.

@karalabe
Copy link
Author

Ah, I may have answered in not the best place, linking it here too. It's relevant for both discussions.

#45 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants