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

[Question] Is SharedData the same as Isolate Groups in Dart v2.15? #6

Closed
leonardovinsen opened this issue Dec 19, 2021 · 12 comments
Closed
Labels
question Further information is requested

Comments

@leonardovinsen
Copy link

First of all, thanks for the great package! Your package has helped me a lot in porting a Java codebase that utilized Thread Pools into Dart code.

In the said codebase, I have used SharedData to share huge data structure (a Map of deeply nested objects) between the isolates. Is it the same as Isolate Groups introduced in Dart 2.15? If it's not, could it theoretically improve the performance of SharedData?

Thanks!

@gmpassos
Copy link
Contributor

Hi,

An Isolate group is not the same thing than a async_task's SharedData.

I'm looking for the new feature for some time:
dart-lang/sdk#46754 (comment)

The new Isolate group for the Dart VM means that 2 Isolates that are in the same groups uses less resources to exists, since they share the same Garbage Collector and same JIT and code tree. With that it takes lees time to create a new Isolate, what is beneficial for parallelism, since reduces the time to allocate a new "Thread" (a common bottleneck in parallelism) and also allows a much higher number of Isolates in the same VM, since they use much less memory.

The Dart 1.5+ will increase performance of async_task, since each Isolate (used to create the parallelism) will be able to communicate faster and also the multiple Isolate will work better, sharing the same GC. Note that async_task already have a pool of Isolates to reduce the allocation time for an Isolate.

@gmpassos gmpassos added the question Further information is requested label Dec 19, 2021
@leonardovinsen
Copy link
Author

Very interesting read.

Based on what I understood in that thread:

  1. Sharing data between multiple AsyncTasks through SharedData will be up to 8x faster?
  2. More Isolates can be spawned in the same VM, so theoritically increasing the performance further?

Lastly, any plans on updating async_task to reap the benefits of Dart 2.15? I'm excited for these changes because the Dart port that I worked on is up to 20x slower than the Java version. Any improvement will be great!

Thanks!

@gmpassos
Copy link
Contributor

Can I see a sample of what you are porting from Java?

@leonardovinsen
Copy link
Author

Sure thing. I've put the relevant bits in this gist https://gist.github.com/leovinsen/88fbea883fc426cf224ff702a273bc34

@gmpassos
Copy link
Contributor

FYI:

I use this class to "benchmark" code:
https://pub.dev/documentation/statistics/latest/statistics/Chronometer-class.html

@gmpassos
Copy link
Contributor

gmpassos commented Dec 21, 2021

I recommend to reduce your AsyncExecutor parallelism parameter, since this should be proportional to the number of cores that your device has. Maybe 2-4 is enough for your case. There's no advantage to allocate more Isolates than the number of threads that your OS can handle. Unless each Isolate spend a significant time with IO, what actually release CPU time to other threads.

In Java, allocate 64 threads for a 4 core CPU won't be good, but with Isolates this issue will be more visible, since each Isolate, even on Dart 1.5, is heavier than just a new native thread.

It's recommended for an application to not allocate all its threads for parallelism, since your device still needs at least 1 core to render UI and OS stuff, and you don't want to see the device to hang.

When running a heavy code in a dedicated hardware for that you won't bother to see the OS sometime hang 1/2 of second for accumulated OS things and usually you don't have an UI to render. But for a final user device you can't generate this scenario.

@leonardovinsen
Copy link
Author

I changed parallelism to 4. There was no change in execution speed, but you're right there's no more jank in UI.

To be honest, I have not figured the cause of slow performance in my Dart code compared to the Java code. And my benchmark methodology is far from accurate (Dart running on my machine vs a Spring project running on an AWS EC2 instance).

Lastly, thank you for sharing your knowledge, it was interesting to learn some things that can't be found on the official Dart docs. I'll try to figure out the problem, and test the latest version of async_task on my project.

@gmpassos
Copy link
Contributor

You will need:
https://dart.dev/tools/dart-devtools

Basically just create a benchmark code, that runs what you want to test intensively and automatically and use the parameter --observe:

dart run --observe my_benchmark.dart

Then you will see a localhost URL for the Dart VM Observatory. Try the CPU Flame Chart, helps a lot!

@leonardovinsen
Copy link
Author

Thanks for the tip, will surely try it.

And wish you happy holidays :)

@gmpassos
Copy link
Contributor

Thanks. Happy holidays too!

@leonardovinsen
Copy link
Author

Hi @gmpassos, I hope you are well.

May I ask for your email address? There's something I would like to discuss

@gmpassos
Copy link
Contributor

gmpassos commented Jan 9, 2022

I have just sent you an email...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants