Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



I changed it to use Cow<str>, performance improved from 121.02 MB/s to 278.66 MB/s

https://github.com/rectalogic/jsonparser


Good job!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: