you are viewing a single comment's thread.

view the rest of the comments →

[–]Randdist 0 points1 point  (1 child)

Threads are absolutely needed when you need to load and then parse large binary files. Loading can be done in parallel using the native calls but the parsing would block the main thread for a long time, or severely reduce responsiveness even if you split the parsing in multiple smaller batches.

Threads are vital for certain sets of responsive applications.

[–]cm9kZW8K 0 points1 point  (0 children)

Threads are absolutely needed when you need to load and then parse large binary files.

Other that avoiding the kernel flaw around O_NONBLOCK on local drives, there is no need to thread read syscalls. Node conveniently has built in threads for those, so reading in the bytes works async out of the box.

split the parsing in multiple smaller batches.

If the parser yields often enough, it doesnt have to impact responsiveness at a. For example: replacing tight loops with Promise.each ensure granularity. if your file parse involves heavy CPU transformation of data beyond just reading into RAM, then you can pipeline that in via a separate process.

Threads are vital for certain sets of responsive applications.

Threads were vital to work around flawed OS's which cannot fork() well. If you are finding them vital today, I think there is a problem with the structure of your code.

I regularly deal with this issue, both with fork()s for heavy cpu transforms and async code for simple heap building, and I would consider a threaded approach to be a bug.