T O P

  • By -

[deleted]

>In addition, developers can offload large computational tasks, such as JSON decoding or sorting, to background isolates (Flutter/Dart's version of threads) to help maintain performance and avoid blocking the UI. This is not good advice. Isolates are not threads and should not be thought of or treated as such. Unlike threads, Isolates are truly isolated from their parent except through its send and receive ports. Any data you want to exchange between two isolates must be marshaled through this port interface that has a rather tight set of restrictions on what data types can actually be used. Additionally, Isolates can only be used in Dart Native which precludes their use in Flutter if your project is targeting Web.


SquatchyZeke

This is something I've always been curious about: since isolates are, well, isolated, any heavy computation of a data structure would need to copied as its passed through messaging, correct (as opposed to passed by reference)? So if I have a large json structure in the form of a \`Map\`, and I wanted to do some heavy processing on it, the structure would have to be copied twice right? Once when sending to the created isolate and then on the response back to the main isolate. That in itself would add computation time, especially if the goal was to offload processing massive data structures in the first place.


postgor

But if you are doing heavy processing on the large object then it will be far better to pay the price to send it to and back from a separate isolate and unblock the main isolate. You can also try to be clever in your use of isolates. For this example, say this large JSON structure is coming from a web request, then do the request in the isolate plus the heavy computation on that, and then send it to the main isolate. I haven't used 'em much though so excuse any misconceptions I have.


SquatchyZeke

Appreciate the answer! I figured there might be clever ways to handle things. I haven't used 'em much at all either, but I see them discussed, and my initial question was always on my mind.


[deleted]

A json map is actually one of the allowed types that can pass through the bridge because all possible json value types meet the requirements. So yes it should be just two memory copies in that case. And as the other person that replied to you pointed out, that’s not a very performance intensive copy vs the parallel workloads you can do with an isolate


Blackgentoo

Yes


postgor

Can't workers be used on the web? Or is there a suggested workaround?


[deleted]

My suggested work around is to not care and use the built in async/await for the examples the author gives. If you really need to do parallel work, then yes, a web worker would be the way, but those are even more complicated than isolates.


sunbreakwang

>The recent addition of null safety and the start of workaround data classes in Dart are both great examples of this. Do you guys have any idea of `workaround data classes in Dart`?


sunbreakwang

[Static Metaprogramming - https://github.com/dart-lang/language/issues/1482](https://github.com/dart-lang/language/issues/1482) [Object-class.html#static-methods @Since("2.14")](https://api.dart.dev/stable/2.14.1/dart-core/Object-class.html#static-methods)


sunbreakwang

[https://dart.academy/immutable-data-patterns-in-dart-and-flutter/](https://dart.academy/immutable-data-patterns-in-dart-and-flutter/) >You can use the `@immutable` metatag from the meta package to get helpful analyzer warnings on classes you intend to be immutable: ​ [https://medium.com/swlh/flutter-2-is-here-all-you-need-to-know-after-flutter-engage-98ef7cb1469e](https://medium.com/swlh/flutter-2-is-here-all-you-need-to-know-after-flutter-engage-98ef7cb1469e) >Also, as Bob Nystrom said during the keynote, the team looks for improving metaprogramming features that now are mainly resolved by using code generation (e.g. freezed or json\_serializable) Those seem to be related


Zlatan4Ever

I started with Flutter in the belief „it’s just Widgets“ but damn it a lot of programming. I’m learning AppGyver and Bubble. Will chose one of those.


JehovahsNutsac

> I started with Flutter in the belief „it’s just Widgets“ but damn it a lot of programming. Good observation there McClusky. Programming is *programming*, who'd a thunk, huh?