News for hackers. Stuff that matters.
Re:Parsing JSON in 500 lines of Rust by thrance on Wednesday February 19, 2025 @05:42AM (#43100687)
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.

Re:Parsing JSON in 500 lines of Rust by rectalogic on Wednesday February 19, 2025 @03:20PM (#43107064)
I changed it to use Cow<str>, performance improved from 121.02 MB/s to 278.66 MB/s

https://github.com/rectalogic/jsonparser

Re:Parsing JSON in 500 lines of Rust by thrance on Wednesday February 19, 2025 @07:04PM (#43109456)
Good job!