Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: note JavaScript is not single threaded #6848

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

benjamingr
Copy link
Member

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 format to ensure the code follows the style guide.
  • I have run npm run test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@benjamingr benjamingr requested a review from a team as a code owner June 19, 2024 13:15
Copy link

vercel bot commented Jun 19, 2024

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

@ovflowd
Copy link
Member

ovflowd commented Jun 19, 2024

If I recall this document was a port of the original guide written many years ago, so not sure who even wrote this initially.

Copy link

github-actions bot commented Jun 19, 2024

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 🔗

Copy link

github-actions bot commented Jun 19, 2024

Unit Test Coverage Report

Unit Test Report

Tests Skipped Failures Errors Time
131 0 💤 0 ❌ 0 🔥 5.441s ⏱️

Copy link
Member

@canerakdas canerakdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joyeecheung
Copy link
Member

I wonder if there's a better way to describe this. What happens in Node.js currently is:

  1. 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)
  2. 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.

@nazarepiedady
Copy link
Contributor

@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.

@bmuenzenmeyer
Copy link
Collaborator

This PR will need to be rebased or recreated now that #6850 merged.

@benjamingr
Copy link
Member Author

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

AugustinMauroy

This comment was marked as off-topic.

Copy link
Contributor

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as it is, I think this resource could do with a little cleaning.

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

Signed-off-by: Benjamin Gruenbaum <benjamingr@gmail.com>
@mikeesto mikeesto added this pull request to the merge queue Jul 9, 2024
Merged via the queue into main with commit d6695fe Jul 9, 2024
14 checks passed
@mikeesto mikeesto deleted the slightly-correct-event-loop-guide branch July 9, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants