doc: note JavaScript is not single threaded
Honestly I appreciate the effort and don't have time to go over the whole thing but there are plenty of inaccuracies in this document.
This PR fixes the first one I noticed - JavaScript as a language is not single threaded. Nor has it ever been, and multithreaded JavaScript execution dates back at least 10-20 years
Description
Validation
Related Issues
Check List
- [ ] I have read the Contributing Guidelines and made commit messages that follow the guideline.
- [ ] I have run
npm run formatto ensure the code follows the style guide. - [ ] I have run
npm run testto check if all tests are passing. - [ ] I have run
npx turbo buildto check if the website builds without errors. - [ ] I've covered new added functionality with unit tests if necessary.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated (UTC) |
|---|---|---|---|
| nodejs-org | ✅ Ready (Inspect) | Visit Preview | Jul 8, 2024 9:38pm |
If I recall this document was a port of the original guide written many years ago, so not sure who even wrote this initially.
Lighthouse Results
| URL | Performance | Accessibility | Best Practices | SEO | Report |
|---|---|---|---|---|---|
| /en | 🟢 97 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/about | 🟢 99 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/about/previous-releases | 🟢 99 | 🟢 100 | 🟢 100 | 🟢 92 | 🔗 |
| /en/download | 🟢 100 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/blog | 🟢 99 | 🟢 100 | 🟢 100 | 🟢 92 | 🔗 |
Unit Test Coverage Report
Unit Test Report
| Tests | Skipped | Failures | Errors | Time |
|---|---|---|---|---|
| 131 | 0 :zzz: | 0 :x: | 0 :fire: | 5.441s :stopwatch: |
I wonder if there's a better way to describe this. What happens in Node.js currently is:
- In general, each libuv event loop pairs with one JS execution thread. There are 7 threads in total by default: 1 main thread (which executes JS and runs the event loop), 4 V8 task runner threads, 1 V8 delayed task runner thread, 1 inspector I/O thread; If any async operations are initiated, 4 more threads will be spawn by the libuv thread pool, and there will be 11 threads in total. (Sometimes additional threads & event loops are spawned for e.g. watchdog for Ctrl+C signals, but those are on-demand)
- When we are talking about a single Node.js instance (instances = main instance or Worker thread instances), each of them has 1 JS thread which runs one event loop. Every Worker spawn adds one more thread into the process (e.g. if the application does some async operation in the main thread, spawns a worker, and then also does some async operation in the worker, there would be 12 threads in total)
To emphasize that one can spawn threads from JS, maybe it's clearer to just mention Workers. But when we are talking about event loops, they do have a 1-1 correspondance with JS threads (each worker gets their own event loop). Or we can just drop "despite the fact that JavaScript is single-threaded" completely since it's not exactly clear what this is talking about in this context.
@benjamingr, you are correct because the language itself can not be described as single nor multi-thread because these specifications have to do with its interpreters and runners.
But I think the usage in this document could be because currently, many programmers associate the language to its interpreter.
To me, it would be better if we say that Node.js not JavaScript is single-thread.
This PR will need to be rebased or recreated now that https://github.com/nodejs/nodejs.org/pull/6850 merged.
To me, it would be better if we say that Node.js not JavaScript is single-thread.
That's also not true (e.g. https://nodejs.org/api/worker_threads.html :D ). We can add Node.js executes a single thread of user JavaScript unless other threads are explicitly created by the user or libraries, not sure that helps.
@bmuenzenmeyer I'm not sure what that means feel free to edit this branch