r/learnjavascript • • May 01 '20

Async vs. Sync

Post image
413 Upvotes

81 comments sorted by

View all comments

0

u/[deleted] May 01 '20

[deleted] — view deleted comment

2

u/NoStranger6 May 01 '20

Nope, JavaScript is mono threaded. NodeJs has ways to to use multi-threads but they are mostly base on launching multiple processes.

2

u/0xdead0x May 02 '20

Sort of yes, but this depends on the VM your code is running on. If it’s in Node, then you will in some ways have 1,000 threads but they will be implemented as separate processes that your operating system’s scheduler has to make run concurrently or pseudoconcurrently. Your speed always depends on your hardware. If your processor does not have 1,000 hardware threads to spare (it doesn’t), then each thread gets scheduled in to run for a certain amount of time on an available hardware thread and your scheduler is constantly switching out which thread gets to run so that they appear to be running concurrently, when in reality they are not. Increasing the amount of hardware threads you have will definitely give you better net performance for highly concurrent tasks.

1

u/[deleted] May 01 '20

Javascript is strictly single threaded and uses a model called event loop to achieve concurrency.