News for hackers. Stuff that matters.
Re:Greenlet – Move an async function into its own thread in ... by untog on Monday January 29, 2018 @10:49AM (#16258139)
JSON parsing (also in the async function) is CPU-heavy, though. If you had a huge, huge amount of JSON it might be worth it. Maybe.
Re:Greenlet – Move an async function into its own thread in ... by Klathmon on Monday January 29, 2018 @11:05AM (#16258239)
Not in this case, because copying data to and from a web-worker uses "Structured Copy" which is about as fast as JSON unmarshaling, but in this case it's actually doing significantly more work:

* read request

* parse from JSON to an object

* read the data from the object in the worker to the main thread

* create a new object in the main thread with the data from the worker

Those last 2 steps are about as slow as a JSON.stringify and JSON.parse, and are completely unnecessary. As others have said, adding some filtering to the example makes this example worlds better.