-
Notifications
You must be signed in to change notification settings - Fork 45
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
Consider removing additional arguments to postTask #18
Comments
Coincidentally, I was just discussing this with @developit this week. I agree and think that would simplify things and be more future-proof w.r.t. passing things to the callback (e.g. One thing Jason brought up was if in the (perhaps distant) future we were able to ship things to a worker through the same API, then having the arguments might be advantageous (@developit please correct me if I butchered that). But I think that might be too far off to consider now? A separate API or even putting the args in the options bag might work for that case. |
Passing the arguments eliminates the need to create a new function so it's good for hot code that posts a lot of tasks. |
While I think we want to be sensitive to overhead concerns, I think some small amount of overhead could be worth the future-proofing, and I think we could always add an args value to the PostTaskOptions dictionary if we proved it was worth it. We're still trying to figure out what to do with the API shape for some follow-up work (yield and task context), and passing something to postTask's callback is a leading option, which makes me favor removing the arg passing for now. Also, we'd want to understand this better:
|
@shaseley my intuition is that it should be faster to use a closure as well, since that avoids the ScriptWrappable and v8::Persistent handle creation overhead. Those are also created on the v8 heap just like the Function instance. Tracking all the gc roots through Oilpan is also not free, so letting the arguments be retained by the Function in v8's heap should be cheaper from a GC cost perspective. Note that a single object like the Function for the closure is very cheap when compared to what happens inside postTask. v8 makes objects for all kinds of things so it's pretty hard to avoid allocations anyway (ex. even floating point numbers are boxed in many cases) |
No. Passing params just seemed intentionally similar to setTimeout and setInterval so I assumed this feature is good for performance. Maybe it was 20 years ago but not now?
Just in case, my concern was the initial overhead to create a different closure each time, not the repeated invocation of the same one. |
Not sure. Like @esprehn mentioned, arrow functions weren't an option then, so maybe it was more about ergonomics and functionality? But now designing with arrow functions in mind, I think removing the args makes sense.
Ack. In the perf tests, I called |
Other quite minor advantages of native calls via the [now removed] additional parameters:
There's a workaround for both of these problems though: using |
It's not clear why anyone would want to pass additional arguments to the callback through postTask itself instead of using an arrow function. I think setTimeout did this because it predated arrow functions? I think it would be nice to avoid having that extra complexity in postTask and to use arrow functions instead.
becomes
This is also safer for long term evolution of the API. If postTask was to change what arguments it passes into the callback it would break the first form because it would shift down the extra arguments. The second form let's us change what postTask forwards in the future in a backwards compatible way.
@shaseley
The text was updated successfully, but these errors were encountered: