3 ms·
What I don't like about that approach is that it still copies into temp. buffers. The normal tape approach is to reference everything via int indices and keep t
by rurban 7y ago
What I don't like about that approach is that it still copies into temp. buffers. The normal tape approach is to reference everything via int indices and keep the input buffer as is. This works also concurrently and with streaming. I don't see the need to copy at all. You don't need \0 delims for strings, just use the mem* API everywhere, all sizes are known.
And API wise filter hooks are needed to skip unneeded arrays or objects. This would also save a lot of unneeded buffering.
- eska 7y agoThey're using those \0 to find bit patterns with SIMD instructions. Their approach would fundamentally not work if they were unable to modify the input.
- dr_zoidberg 7y agoI'm going a bit meta here: I absolutely love that the first comment I see coming into the discussion is someone arrogantly telling (us, not the author) how to do their job, when evidently we're looking at one of the most thought-out, better engineered pieces of software there is in their area (JSON parsing). What's more, the authors of simdjson show a lot of benchmarks, explain how they got there, they provide their effort in a liberal license, and yet... This peep over here comes to tell us how he thinks that's wrong... Just got a bit ranty. And sorry eska for taking a bit of your comment for it. You tried to give some sense into this guy. Edit: at first I thought this was the top comment because of being newer... Nope, it's the top comment alltogether. Followed by another comment about the same time as old of someone telling how great this library is and how they're using it in production with a rust wrapper.
- jkeiser 7y agosimdjson does not modify the input, fyi. Rather than \0, which isn't really a part of JSON, the SIMD instructions search for whitespace and JSON structure like commas, colons, etc.
- eska 7y agoYeah, sorry I didn't feel like giving some guy who hasn't even read the article a full explanation. However I saw in a presentation on YouTube that these characters are replaced (e.g. ") to then apply SIMD instructions. This implies copies and allocations. But these are necessary, and it would not be possible to achieve this with indices.
- jkeiser 7y agoStreaming and selective parsing are good things, and something we're looking into for the next set of features. Note that there are real speed gains to be had by not being selective. The CPU is normally sprinting ahead, executing future instructions before you even get to them, and every branch can make it trip and land flat on its face. We've found we have to be very careful with every branch we introduce. I've tried to introduce branches that skip tons of code and ought to make things a ton faster, but which instead slow it down.
- rurban 7y agoThat's of course true. Branching is costly and malloc is costly. But there is a need to filter objects and arrays in the 2nd part behind the parsing, in the conversion to your language/data. With a slower seperate function of course. Parsing is the neglible fast part, converting it into your business objects is the slow part. This is usually done with the 2nd tape step. This involves a lot of malloc's, and you really want to skip the unneeded parts and filter it upfront. Still thinking how to design my new JSON parser around simdjson.
- jkeiser 7y agoAgreed, we're thinking it through too. Most parsing of JSON could be done almost without any second stage at all, or at least with a direct-to-user-struct/array, if you had the right API.