The simdjson parser has some allocation to do when it is initialized, and currently simdjson_nodejs recreates the parser every single time.
We could use napi's napi_set/get_instance_data to store an instance of the parser for each JS worker thread, keeping that internal memory around. We would have to extract the document from the parser at the end of the parse with std::move, but it would get rid of the internal buffer allocation and even keep them hot--which seems likely to more than counterbalance any performance degradation we'd get from said extraction.
If we could tell whether the user kept any instances of the document around when they call parse() again, we could even use a copy-on-write scheme and only move the document away if the user calls parse() again while there are still live document instances in JS (many people just read a doicument extract what they want, and throw away the JSON before doing anything else, so it would be a win for a lot of cases)..
@lemire ^^ relevant to simdjson's ability to work well with bindings.
The simdjson parser has some allocation to do when it is initialized, and currently simdjson_nodejs recreates the parser every single time.
We could use napi's napi_set/get_instance_data to store an instance of the parser for each JS worker thread, keeping that internal memory around. We would have to extract the document from the parser at the end of the parse with std::move, but it would get rid of the internal buffer allocation and even keep them hot--which seems likely to more than counterbalance any performance degradation we'd get from said extraction.
If we could tell whether the user kept any instances of the document around when they call parse() again, we could even use a copy-on-write scheme and only move the document away if the user calls parse() again while there are still live document instances in JS (many people just read a doicument extract what they want, and throw away the JSON before doing anything else, so it would be a win for a lot of cases)..
@lemire ^^ relevant to simdjson's ability to work well with bindings.