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

New page: Concurrency in Dart #3696

Merged
merged 14 commits into from
Dec 8, 2021
Merged

New page: Concurrency in Dart #3696

merged 14 commits into from
Dec 8, 2021

Conversation

kwalrath
Copy link
Contributor

@kwalrath kwalrath commented Dec 3, 2021

Still needs some finishing work, detailed at the bottom of the doc.

staged: https://kw-dartlang-3.web.app/guides/language/concurrency

Still needs some finishing work, detailed at the bottom of the doc.
@google-cla google-cla bot added the cla: yes Contributor has signed the Contributor License Agreement label Dec 3, 2021
@kwalrath kwalrath marked this pull request as draft December 3, 2021 02:02
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

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

src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
which enables the background worker
to send messages to the main isolate.

2. Next is the call to `Isolate.spawn()`,
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

@kwalrath kwalrath Dec 6, 2021

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.

Copy link
Contributor

@aam aam Dec 7, 2021

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.

Copy link
Contributor Author

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)

src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
@kwalrath
Copy link
Contributor Author

kwalrath commented Dec 7, 2021

ptal @mit-mit, @johnpryan, and anyone else who's interested. New staged location:

https://kw-dartlang-3.web.app/guides/language/concurrency

@kwalrath kwalrath added the st.blocked Issue cannot continue until another action completes label Dec 7, 2021
@kwalrath kwalrath added this to the Next stable release milestone Dec 7, 2021
@kwalrath
Copy link
Contributor Author

kwalrath commented Dec 8, 2021

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

@kwalrath kwalrath marked this pull request as ready for review December 8, 2021 04:17
Co-authored-by: Parker Lougheed <parlough@gmail.com>
Copy link
Member

@parlough parlough left a 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.

Copy link
Member

@mkustermann mkustermann left a 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.

src/_guides/language/concurrency/index.md Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
src/_guides/language/concurrency/index.md Show resolved Hide resolved
src/_guides/language/concurrency/index.md Outdated Show resolved Hide resolved
kwalrath and others added 2 commits December 8, 2021 09:47
@kwalrath kwalrath merged commit 430ca03 into master Dec 8, 2021
@kwalrath kwalrath deleted the kw-concurrency branch December 8, 2021 17:52
@kwalrath kwalrath removed the st.blocked Issue cannot continue until another action completes label Dec 9, 2021
@kwalrath
Copy link
Contributor Author

kwalrath commented Dec 9, 2021

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.

I've created a followup issue: #3720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Contributor has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants