Async JSON parser/serialiser
Is there some maintained asynchronous JSON parser/serialiser for nodejs?
I don't need it to be fast. I need it to yield often to let other tasks run in parallel.
I don't need it to support browsers. NodeJS is enough for my case.
Once upon a time, there was BFJ https://gitlab.com/philbooth/bfj which fits the bill perfectly, but, unfortunately, is not maintained anymore. It's still usable, I guess. But 3 years is a lot of time.
Posted Sep 1, 2023, 5:15 PM UTC
you can build one using worker threads
I can't. that would be… many-many thousands of threads. no point to use nodejs at that point. I want my greenlets :)
-v please
Why would that result in thousands of threads.. and whats the issue with nodejs here?
Worker threads are represented as real OS-level threads, as far as I remember and those have overhead. NodeJS app occupies single thread by default (there are some helper-threads used by NodeJS internally, but that is irrelevant here) which means that OS has less things to do and asynchronous queues for I/O are really light-weight. That’s exactly what makes NodeJS (and other asynchronous frameworks great) — they saturate cpu cores with less overhead
single threaded code can only ever saturate 1 cpu core.
The most efficient way to parse many json file is to create one thread per cpu core an queue them accordingly
if you decide to try, the very first example on the docs page is how to do almost exactly what you want https://nodejs.org/api/worker\_threads.html
Why many thousands? One worker can parse many json files (one after another) without affecting the main thread. What are your actual requirements?