Isolates (Technique of the Week)
Вставка
- Опубліковано 22 кві 2024
- If your Flutter app has jank due to a heavy computation, use Isolate.run() to move that computation to a new isolate.
Isolate class → goo.gle/3vvBKi4
Use isolates in your Flutter app → goo.gle/43DiXxL
Article about Isolate.run → goo.gle/4acRwxn
Watch more Technique of the Week → goo.gle/FlutterTechnique
Subscribe to Flutter → goo.gle/FlutterYT
#Flutter #TechniqueOfTheWeek
Speaker: Eric Windmill
Products Mentioned: Flutter - Наука та технологія
WOah! Technique of The week, a very lovely initiative by the Team! Hoping to see a lot more useful stuff here!!
Should have mentioned compute at the end.
its the same now
this series will be lit 🔥
플러터를 죽이지마세요 최고의 앱제작 프레임워크입니다
This is super important when you're dealing with AI and images!
Used this type of function for object detection of foods in a diet app I made. App wasn't great, but learning about this was very useful!
what a great presentation series!!
Really useful video, can't wait for the next "Technique of the week"!
Very interesting. I didn't know about isolates. Will be researching them a bit more now. Thanks for this!
thank you Flutter Team!
This is freaking awesome and life changing
Can you use isoltes for Web?
I’m like like this segment. I can already tell.
Excellent!
from what i remember isolates where implemented different than what they describe in the video, this seams legit easy!!
You can use it with background elements, such as apps that allow users to listen to sound in the background while continuing to use the app.
Yeah I was just thinking, I have an app using geofencing and this would be a good candidate to use while it listens to the realtime geofence reporting
Concise and clear 👌
Interesting series, I hope we see more of it!
finally Isolates!
Thank you 🎉
This is what I needed 👍, thank you Flutter 🥳
Thanks!
Proud to be Flutter Developer
so great!!! 😀
I love this video, thank u
it was about time!!!!
As much as I love the idea of this. I feel like this should have been implemented into flutter itself behind the scenes.
As soon as I try to implement Isolates, with either this code or with flutter_isolate, I run into one problem after the next, such as:
Unhandled Exception: Invalid argument(s): Illegal argument in isolate message: object is unsendable - Library:'dart:async' Class
NoSuchMethodError: No top-level getter 'xxx' declared.
Null check operator used on a null value
Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast
Even with top level functions, @pragma('vm:entry-point') and everything else - it just doesn't like my set up project.
Seems too rough around the edges to use at the moment. Would be much nicer to just use it like we use the "async" word.
flutter is growing so fast
good job flutter team
amazing
Perfection
Flutter all the way!!!! 💗
AWESOME
Waiting is end now 🤩
Technique of the week:
It will be really useful after Widget of the week. ❤
Son los mejores
awesome
nice
Fire 🔥
Yeah
Yo that's actually huge. more, I need more!
Hello! @flutterdev Just wondering if there might be a chance you could PLEASE do a intro to flutter series?
I know that one was done 2 years ago but you can see my notes there - it could use some updating to say the least... in fact, to be blunt, it needs to be redone entirely, if you ask me. Again, see my notes on that playlist ( on the 3rd or maybe fourth video) long story short please please please please please do an intro to flutter series!
What if we load the file inside the isolate instead of before it?
For the algorithm!
The final statement could benefit from some further explanation (outside the scope of this original video):
"Although the callback doesn't have arguments, it captures the variables it needs because it's a closure."
An explanation of "closures" specifically would be helpful, but also why I would need to be concerned with the "capturing of variables" in the first place.
Until you mentioned, "although [it] doesn't have callbacks," I hadn't even considered why that would be relevant-closure or not.
When is it supported web platform
Isolates.run() doesn't work on web - so Compute() method runs the computation on the main thread on the web, but spawns a new thread on mobile. So to steal the example from the docs that made it click for me, compute(fun, message) is equivalent to await Isolate.run(() => fun(message)).
Got this answer from @KhanhFlutter
But we can't use isolate in web
What a difference between Isolate.run() and an existing compute() function? Because it works not only in Flutter but in pure Dart too?
Isolate.run doesn't work on web - so Compute() method runs the computation on the main thread on the web, but spawns a new thread on mobile. So to steal the example from the docs that made it click for me, compute(fun, message) is equivalent to await Isolate.run(() => fun(message)).
Cool
Now make Isolate work in web apps!
lit!
Future async functions don't run in another thread as well?
No they don't. They work like async functions in Javascript.
so Dart isolates are Golang go() right?
No, the goroutine share the memory, Dart isolates does not.
🔥🔥🔥
In my opinion nothing beats Kotlin Coroutines .
You should add support FOR WEB!!!
you can implement service workers on web if really needed.
@@PhilippeMakzoume Well I dont want yo touch Javascript for anything, flutter should include web support in Dart
What's the difference between compute() method and Isolate.run()?
Basically none, except that .compute() is "safe" to run in web as well, with the caveat that it will not run in another thread/worker. If you dig into the compute function you will quickly see it's very minimal implementation :)
@ awesome tnx
How is this similar or different to async/await
It is different, async/await still run on the same thread in which the UI loads and can reduce the frame rates.
finally
Por favor resuelvan la incertidumbre van a cerrar o no? va hacer una tecnología muerta o no? porque no vale la pena aprender algo que no te proyecte a futuro se que para que una tecnología muera no es de la noche a la mañana pero si seria bueno saber?😭😭🙏🏻
So it’s like assynchronous code for the UI? 😂
Anyone reading this, and wondering if isolates work in web, they don't. The design of isolates in itself isn't straight forward due to static data requirements without context passing like other languages but on web, only web workers work with quite a bit of work.
Not disuading anyone, just putting information out there.
just make sure you don't get a race condition
Is that possible though, because the memory isn't shared. Unless, we do IO/File operations inside of it which I guess doesn't make sense to do there
@@krtirtho Memory isn't shared? What about the closure? Is everything copied?
@@HankyUSA yeah its copying which means it isn't really optimal to do like in the video for large files.
@@hellpunch9414 Indeed, in cases like that you'd probably want to stream the file over to the Isolate a bit at the time.
So you couldn't give it more conventional name like Thread.
Like if you have never used it
But this is powerful stuff here
I have used compute() functions instead isolates
@@nialegu it's the same thing internally
This is not even useful in most cases: you cannot use dart:ui on an Isolate, this is just ridiculous. Spawning Isolate takes more time than deserializing JSON (below 2 mb) on the main thread
It was long time ago when isolates were slow.
Now, with Isolate Groups introduced in Dart 2.15, spawning and disposing of an isolate is blazingly fast.
@@sergey_molchanovsky That's good news
@@sergey_molchanovsky I tried Isolate.run() mentioned in the video, it took 300 ms to spawn, slower than deserialization on main thread (50 ms). Maybe I overlooked something?
@@sergey_molchanovsky I tried Isolate.run() and it took 300 ms to deserialize whilst on the main thread it was only 50 ms, so I cannot understand what "blazingly fast" means
@@sergey_molchanovsky maybe I overlooked something, but deserializing json with the method mentioned in the video took 300 ms when I tried it and only 50 ms on main thread
Hope youtube won't delete my comment for the 3rd time
can Google kill flutter
Thank you google you’re trying to kill your best framework 💀 WHY?
Bro tu que sabes ingles que sabes de la noticia encerio va a morir el framework?
First comment!
flutter will be die
Wow...maybe you should mention that flutter is so awesome that does not support isolates on web. 2/10
Fire 🔥
nice
🔥🔥🔥🔥🔥
nice