If you inject main executor into an actor, what happens exactly? How would it compare with sync code from a pure execution speed standpoint? (Or is that a naive question?)
When on the background executors I noticed that there is a slight performance cost to context switching as the execution will hop to those background executors and then back to the main. Whereas if they're both on main then it felt like there isn't as much lag, for the simple case of small work on the actor.
Could you clarify what you mean by “inject main executor into an actor”? Do you mean like you’ve implemented unownedExecutor in a custom actor and are returning the main actor’s executor from that?
Could you clarify what you mean by “inject main executor into an actor”? Do you mean like you’ve implemented unownedExecutor in a custom actor and are returning the main actor’s executor from that?
Yes, that would be the idea. It's just a curiosity if that is something that one can do, and if so, what are the consequences for the async/await calls.
It would be effectively no different than using MainActor, but you'd have to either manually await calls to it or use a custom assumeIsolated, because the compiler won't pick up the fact your custom executor is the same as the MainActor's.