How expensive are coroutines on iPhone?

I’ve recently discovered coroutines, which make a sequence of events, separated by time for instance, easy to do, or allows me to delay a bit of script logic very easily - i.e. play the animation 5 seconds from now. I’m developing for iOS however, so I’m wondering whether coroutines are a good idea on iOS or are they likely to quickly impact performance?

I really don’t want to have to start writing lots of state machines in the Update() method - are coroutines really just handling that boilerplate for me? If I yield return StartCoroutine() am I creating some heavy weight object? What about returning new WaitForSeconds() objects?

I appreciate this might be quite a tough question to answer ‘off the top of your head’, so I guess I am looking for; either someone who has some metrics; someone ‘in the know’; or perhaps someone writing for iOS who is using them and has had either a good or bad experience as a result and is willing to share! :slight_smile:

Thanks in advance

Coroutines are faster than running state machines in Update.

2 years later but maybe interesting for others:

Using Unity 3.5.7 on my old iPhone 4 I did some profiling. As others stated, coroutines are almost for free, but the profiler revealed that instantiating a YieldInstruction could take a measurable amount of time.

So I replaced all:

while (myBool) {
    // do something
    yield return new WaitForEndOfFrame(); // 0.2 - 2 ms every frame


YieldInstruction yieldInstruction = new WaitForEndOfFrame ();
while (myBool) {
    // do something
    yield return yieldInstruction; // no impact

They are a great things and should definitely be used and exploited, they save performance if used correctly.

Have a read up on;