-
Notifications
You must be signed in to change notification settings - Fork 700
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
New page: Concurrency in Dart #3696
Conversation
Still needs some finishing work, detailed at the bottom of the doc.
Visit the preview URL for this PR (updated for commit 75d40c4): https://dart-dev--pr3696-kw-concurrency-awkhphax.web.app (expires Fri, 10 Dec 2021 02:07:30 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: d851bc446d3c4d7394c5406c6f07255afc7075f3 |
which enables the background worker | ||
to send messages to the main isolate. | ||
|
||
2. Next is the call to `Isolate.spawn()`, |
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.
I think it would be really helpful in understanding this if the ports were somehow shown on the diagram
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.
Probably a good idea, but I might not get to it in the first published version.
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.
Noted in followup issue (#3720)
[`send()` method]: https://api.dart.dev/stable/dart-isolate/SendPort/send.html | ||
|
||
{{site.alert.tip}} | ||
The `send()` method can be slow. |
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.
Describe if this slowness is on the sending or receiving side
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.
I don't actually know the answer to this! Which is it? My guess is both.
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.
When send
is used between isolates in different isolate groups(spawned using Isolate.spawnUri
), both sender and receiver are doing similar O(number-of-objects-being-sent) work: serializing done by the sender and deserializing done by the receiver.
When send
is used between isolates in the same isolate group(spawned using Isolate.spawn
), the sender (normally) does more work. The sender validates the message being sent and copies mutable objects of the message for the receiver's consumption. Heap is shared between isolates, so the receiver just picks up a reference to the prepared copy that the sender gives to the receiver. Only further processing that the receiver has to do is to canonicalize/recalculate hashes for certain objects. If no canonicalization is needed, receiver will do no additional work.
Sending immutable(or "shareable") data is done by passing a reference, so no copy is needed and is very fast.
Use of Isolate.exit(port, object)
avoids creating a copy too because it is guaranteed that the sender exits and does not mutate sent data. Because of that Isolate.exit
is faster for sender than regular send
. Sender still has to validate that only allowed objects are being sent, so it still does O(number-of-objects) work.
TransferableTypedData
is similar to regular send
, in that its sender who pays higher price by creating Transferable wrapper around unstructured bytes. There is no object traversal happening though, it is just memory copy, so it is faster than sending structured objects. Receiver gets data in constant time too.
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.
Included in followup issue (#3720)
ptal @mit-mit, @johnpryan, and anyone else who's interested. New staged location: |
Maybe ready to go? I'll take another look tomorrow. I've updated the staged version: https://kw-dartlang-3.web.app/guides/language/concurrency |
Co-authored-by: Parker Lougheed <parlough@gmail.com>
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.
I think this looks in a pretty great place as an initial release, nice job! It's nice to see some fleshed out documentation around these concepts.
If you have a chance, creating an issue with some of the follow-up work you want done would be helpful. A comment may be hard to track.
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.
In general looks good.
Co-authored-by: John Ryan <ryjohn@google.com>
I've created a followup issue: #3720 |
Still needs some finishing work, detailed at the bottom of the doc.staged: https://kw-dartlang-3.web.app/guides/language/concurrency