2 ms·
Do not parse using strip_prefix and then to_string, you're allocating a new buffer after each token! You can use Cow<str> for the result of the "parse string va
by thrance 2y ago
Do not parse using strip_prefix and then to_string, you're allocating a new buffer after each token! You can use Cow<str> for the result of the "parse string value" function, as most JSON strings don't have escapes you can just return a reference to that slice of the buffer, only allocating when there's actually an escape.
In general when writing a parser you should strive to minimize allocations and backtracking.
- rectalogic 2y agoI changed it to use Cow<str>, performance improved from 121.02 MB/s to 278.66 MB/s https://github.com/rectalogic/jsonparser https://github.com/rectalogic/jsonparser
- thrance 2y agoGood job!