opencv_dart icon indicating copy to clipboard operation
opencv_dart copied to clipboard

Can I call async functions for everything?

Open redcurry opened this issue 1 month ago • 2 comments

Is there a performance penalty for always calling async functions? What happens exactly, is a thread always spun up when I call an async function?

redcurry avatar Nov 25 '25 19:11 redcurry

@redcurry hi

Is there a performance penalty for always calling async functions? What happens exactly, is a thread always spun up when I call an async function?

Of course yes, you should use async version for heavy computations to avoid blocking UI, for simple computations, synchronous functions are preferred. I have not benchmarked it but I think it's acceptable if you want to keep UI responsive.

Basically, asynchronous functions are implemented via NativeCallable.listener, which is implemented with SendPort and ReceivePort across different isolates, thus extra cost is introduced.

rainyl avatar Nov 26 '25 07:11 rainyl

OK, that makes sense, thank you. I started by using async in places where I thought was heavy computation, but when I benchmark it, the async version is slower for many of these functions.

redcurry avatar Nov 26 '25 16:11 redcurry