GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — worker: remove workerData option by devsnek · Pull Request #21414 · nodejs/node

Conversation

@devsnek

@devsnek devsnek commented Jun 19, 2018

Copy link
Copy Markdown
Member

to start out my crawl of aligning node's workers with the web, this pr removes workerData.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@devsnek
[worker] remove workerData option
89ac0d4
@devsnek devsnek added the worker Issues and PRs related to the worker_threads module and Worker API. label Jun 19, 2018
@nodejs-github-bot

nodejs-github-bot commented Jun 19, 2018

Copy link
Copy Markdown
Collaborator

@devsnek build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/102/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to the worker_threads module and Worker API. label Jun 19, 2018
@devsnek
devsnek requested a review from addaleax June 19, 2018 22:42
@gireeshpunathil

gireeshpunathil commented Jun 20, 2018

Copy link
Copy Markdown
Member

does this mean now any worker should setup a message loop, if it needs to receive its input?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fishrock123
Fishrock123 suggested changes Jun 20, 2018
View reviewed changes

@Fishrock123 Fishrock123 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

workerData is useful for passing SharedArrayBuffers, as per the test I wrote.

I don't see the point in aligning the API if it is not going to act the same regardless.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Fishrock123
Fishrock123 reviewed Jun 20, 2018
View reviewed changes
Comment thread test/parallel/test-worker-workerdata-sharedarraybuffer.js
@@ -10,23 +10,22 @@ const { Worker } = require('worker_threads');
const local = Buffer.from(sharedArrayBuffer);

@Fishrock123 Fishrock123 Jun 20, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this pr renders this test file irrelevant, as evidenced by it's name.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devsnek

devsnek commented Jun 20, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@Fishrock I'm planning to make it act the same, it's just a lot for one PR. do you think I should just remove that test then?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Jun 20, 2018

Copy link
Copy Markdown
Contributor

Is there a larger write up somewhere of how it can be the same and why we, being not a web browser, should do that?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jun 20, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@Fishrock123 I kind of take the opposite approach. my way of thinking is "why does it need to be different."

I don't think node has any cases where it loses some important functionality by aligning with the existing idea of workers in the ecosystem. that is to say, I think we should have a larger write-up of why we shouldn't align with the ecosystem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jun 27, 2018

Copy link
Copy Markdown
Member Author

ping @Fishrock123 @addaleax

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jun 27, 2018

Copy link
Copy Markdown
Member

I don't think node has any cases where it loses some important functionality by aligning with the existing idea of workers in the ecosystem.

Because Node’s idea of Workers is pretty different from Web Workers – having a full Node.js API available, rather than being sandboxed, for example.

The important question for me was whether we can implement Web Workers on top of the current API, in userland, if we like.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jun 27, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@addaleax we can still stay fairly aligned with the ecosystem by doing stuff like attaching postMessage to global in workers and introducing random mechanics that might be useful but don't align with things like workerData. I don't see a good reason to be different for the sake of difference.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gireeshpunathil
gireeshpunathil requested changes Jun 28, 2018
View reviewed changes

@gireeshpunathil gireeshpunathil left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

looks like my question is abandoned. Asking again with formal process:

does this mean now any worker should setup a message loop, if it needs to receive its input?

If so, I think this change (snuffing out a capability) does not seem reasoable to me; reason of compatibility with another module / technology with similar functions is not compelling.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devsnek

devsnek commented Jun 28, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@gireeshpunathil the loop exists anyway and workerData can't be mocked in the rest of the ecosystem. i'm not talking about just some other module; i'm talking about how the entire rest of the ecosystem interacts with threaded js.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek devsnek mentioned this pull request Jun 28, 2018
only deviate from well-established ecosystem design if necessary nodejs/TSC#557
Closed
@TimothyGu TimothyGu added the tsc-review label Jun 28, 2018
@gireeshpunathil

gireeshpunathil commented Jun 28, 2018

Copy link
Copy Markdown
Member

workerData can't be mocked in the rest of the ecosystem.

Can you elaborate please? isn't this already optional? so what is the need of mocking or simulating?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jun 28, 2018

Copy link
Copy Markdown
Member

The way I see it is this: Node.js is already providing significant non-standard features for Workers, namely the availability of almost all Node.js APIs inside of them. Removing that and restricting to a standard feature set would increase complexity of the implementation and remove significant value.

That makes asking for two-way compatibility pointless. What does make sense is trying to get Workers to a point where they implement the Web API’s feature set, so that you can write code against that API and have it work in Node.js.

gireeshpunathil, TimothyGu, and Mathspy reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jun 28, 2018

Copy link
Copy Markdown
Member Author

@addaleax i'm not against having more stuff or slight differences (e.g. i don't expect us to use EventTarget or implement importScript). however i would still argue that workerData should be removed because it encourages a spawn-per-use model instead of spawn-once-multiple-use model. even in the case that you only need a worker once or twice for some once-time task, the (tiny) extra time of a postMessage isn't going to really affect that.

gireeshpunathil reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gireeshpunathil

gireeshpunathil commented Jun 28, 2018

Copy link
Copy Markdown
Member

@devsnek - I see your point now, and looks reasonable: coupling and decoupling workers on a need basis, with the message loop as the sole communication channel.

However, starting a worker with an optional input IMO is no way harmful to that design, and may be useful for many.

I think retaining the current worker impl. as an infra layer and bringing the feature set that is fully aligned with web worker's expectation, effectively strengthen worker's adoption and usability.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek devsnek changed the title [worker] remove workerData option worker: remove workerData option Jun 28, 2018
@guybedford

guybedford commented Jun 28, 2018

Copy link
Copy Markdown
Contributor

The way I see it is this: Node.js is already providing significant non-standard features for Workers, namely the availability of almost all Node.js APIs inside of them. Removing that and restricting to a standard feature set would increase complexity of the implementation and remove significant value.

That makes asking for two-way compatibility pointless.

This all or nothing thinking does worry me a little.

Build tools can do a lot to fill the gaps here, allowing code written in a "Node" way to work in the browser by shimming the Node modules etc. But there are things that are very hard for build tools to do, and things that are easy to do. Making require work in the browser is easy. Supporting a feature like workerData is hard. I do think it's worth considering browser build tooling costs when there are implementation differences like this one.

devsnek reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented Jul 15, 2018

Copy link
Copy Markdown
Member

Cf. whatwg/html#3823

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jdalton
jdalton suggested changes Jul 16, 2018
View reviewed changes

@jdalton jdalton left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👎

Update:

Per @devsnek's request:
Sorry, was on mobile. I agree with @addaleax's stance on this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devsnek

devsnek commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

@jdalton can you offer a bit more about why you are against this besides 👎"

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RandyBuchholz

RandyBuchholz commented Jul 16, 2018

Copy link
Copy Markdown

I authored the post in whatwg/html referenced by @TimothyGu, that proposes adding parameters to the Worker constructor. It seems workers are getting a lot of attention lately. Thought I'd throw in a couple of thoughts here.

I support the idea of keeping common features on node/html "common", but what is the overall strategy? Without a "meta" workgroup, this can involve a lot of tail chasing. This is a case in point, I'm proposing adding a feature that (basically) exists in node, to html, while this issue is proposing removing it from node.

Node runs in a much richer environment, so I would expect a richer feature set. As long as the signature and behavior of common features match, I don't know that differences are much of an issue, especially since they will never really match. As @devsnek said, it unlikely that features like importScript would make it to node. And at a more fundamental level, now that ES6 has native import/export there is a major cross-compatibility split taking place between require and import/export.

@guybedford said,

"Making require work in the browser is easy. Supporting a feature like workerData is hard."

but what about making import/export work in node? And, I'm not sure how hard workerData is to implement (not knowing the internals), but on the surface, html Worker already accepts an object bag, exposing that seems to get pretty far down the road towards workerData.

With the change, if a goal is html/node consistency, the constructor will still need to accept additional parameters beyond the source:

new Worker(source, { type="...", name="..." }

while name isn't currently exposed, it will be in near browser versions. @devsnek said

however i would still argue that workerData should be removed because it encourages a spawn-per-use model instead of spawn-once-multiple-use model.

but, (don't mean to be a D here) does introducing a breaking change to protect users from themselves and enforce a use-case/architecture preference really make sense? There are valid Spawn-per-use cases, like implementing parallel processing or threaded async. And, since name will need to be accessible for compatibility, a json encoded name, can essentially be used as workerData. Removing workerData may help discourage per-use some, but doesn't really constrain it. Though it does encourage/require using name hacks for cases where constructor parameters are valid cases.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

does introducing a breaking change to protect users from themselves and enforce a use-case/architecture preference really make sense?

Absolutely. Not all users understand how workers really work because, well, you shouldn't have to understand how they work to use them. By that reasoning, the API shouldn't let them do things that hurt performance/etc. Also, its not a breaking change because workers are still experimental.

However that's not really my main reasoning for wanting to drop this. workerData cannot be polyfilled in a browser, so code authored that uses it will require source transforms to be used in browser. I'm a fan of the ability to use tooling to pack things into the browser and from where I'm standing it seems unnecessarily hostile to keep the feature. Your proposal is one thing but it won't happen any time soon (and we can always bring workerData back if your proposal goes through).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RandyBuchholz

RandyBuchholz commented Jul 16, 2018

Copy link
Copy Markdown

Ah, didn't realize they were experimental, and the polyfill reasoning makes sense.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek devsnek closed this Aug 24, 2018
@devsnek
devsnek deleted the remove-worker-workerdata branch August 24, 2018 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gireeshpunathil gireeshpunathil gireeshpunathil requested changes
@addaleax addaleax Awaiting requested review from addaleax
+2 more reviewers
@Fishrock123 Fishrock123 Fishrock123 requested changes
@jdalton jdalton jdalton requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@devsnek @nodejs-github-bot @gireeshpunathil @Fishrock123 @addaleax @guybedford @TimothyGu @RandyBuchholz @jdalton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.