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

unlock worker #4

Closed
wants to merge 2 commits into from
Closed

Conversation

targos
Copy link

@targos targos commented Jan 1, 2023

No description provided.

@targos
Copy link
Author

targos commented Jan 1, 2023

The code is a bit complex to show how we could support parallel work for things other than import.meta.resolve.
I also added a small timeout at the end just so we don't miss any logs (because the process would end without waiting for them, as the worker is unrefed).

console.log('[Main]:', 'Resolve bar');
const barVal = importMetaResolve('bar');
console.log('[Main]:', 'Bar is', barVal);

// Keep the thread alive a bit to get the last logs.
setTimeout(() => {}, 1000);

Choose a reason for hiding this comment

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

Is there some way to check that there are logs in progress that haven’t yet been printed? Like that process.stdout has messages queued or something?

Copy link
Author

Choose a reason for hiding this comment

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

not that I know of

Copy link
Owner

Choose a reason for hiding this comment

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

It's a stream, so is it possible to check whether a stream is empty? Stream::cork() / Stream::uncork() or Stream::on('finished')

@@ -1,28 +1,50 @@
import { deserialize, serialize } from 'node:v8';
import { Worker } from 'node:worker_threads';
import { Worker, MessageChannel, receiveMessageOnPort } from 'node:worker_threads';

Choose a reason for hiding this comment

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

Is the use of MessageChannel required in order to unlock the main thread? I’m thinking that if we could split this into two PRs, where one does the refactor from SharedArrayBuffer to MessageChannel and the other unlocks the main thread, we could use the former to benchmark SharedArrayBuffer vs MessageChannel to know which one is faster; and hopefully either approach can accommodate an unlocked main thread.

Copy link
Owner

Choose a reason for hiding this comment

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

I think they are coupled: postMessage() is instead of (almost all of the) Atomics

@targos targos closed this Jan 15, 2023
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.

3 participants