Download

Multi-cast delegates vs function access in loops: Runtime performance

I’m using loops which iterate over


TArray<UMyActorComponent*>

to call functions in different UActorComponents. I’ve discovered just recently, that multi-cast delegates offer similar possibilities.

Would it improve the runtime performance, if I remove the loops and use multi-cast delegates instead (so I won’t have to iterate over a TArray to access each function). Or are multi-cast delegates not faster in that regard?

Considering the multi-cast delegate still has to iterate over each bound function to call them, I’d guess there is no meaningful difference.

The delegates would probably be slightly slower because the compiler can’t optimize them as well as a simple loop calling the same function on a few objects.

Thanks for the input! I will stick to the loops.