I have to parse a very long JSON text into a JSON object. I tried to measure the runtime using the following code.
var t = process.hrtime()
JSON.parse(jsonStr);
t = process.hrtime(t);
It takes about 0.5 milliseconds, which is quite a lot. because nodejs is single-threaded for its V8 Engine, if this operation is so heavy and frequent, performance will be greatly affected.
Therefore, I plan to write asynchronous JSON.parse in C as a native NodeJS addon, using uv_queue_workso that a heavy operation occurs on another thread using a multi-core processor and avoiding using the main nodejs loop.
The problem is that the V8 object in the JS host cannot be accessed from a thread other than the main thread.
Is there a way that I can parse text and create a V8 object in another thread, and then copy the newly created V8 object to the main stream?
Vg
source
share