Any costs I should know about associated with InvokeRepeating?

Is there any real overhead associated with InvokeRepeating? I have something that runs in Update that I can easily get away with updating, say, 30 times per second instead of every single frame (which in most scenarios means it's being run about 150 times per second; which seems like I have a lot of excess frames to work with, but I'm making a physics game so I need to squeeze out as much performance as possible).

Keep in mind this is for simple "update counter text" type things, so the function itself that is being repeated isn't heavy, but I'm trying to maximize speed and wondering if InvokeRepeating has any inherent performance hits.

If there aren't any problems, I'm going to happily start migrating a bunch of things out of Update, where it seems wasteful to do them every single frame when there's no need.

Also, is there any difference between using coroutines and InvokeRepeating in terms of performance?

more ▼

asked Nov 28, 2011 at 07:12 PM

avatar image

Jason B
1.9k 73 65 82

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

In terms of overhead, the order (from most to least) is Update, coroutines, then InvokeRepeating.

more ▼

answered Nov 28, 2011 at 07:48 PM

avatar image

120k 69 345 765

Ah, that's surprising. Thank you.

Nov 28, 2011 at 08:56 PM Jason B

Specifically, InvokeRepeating is about twice as efficient as a coroutine when it repeats, but the "wait" part for both has no appreciable overhead (as opposed to Update, which always has overhead).

Nov 28, 2011 at 09:17 PM Eric5h5

Really useful to know. I've been using coroutines a lot but end up yielding a new WaitForSeconds() each time and I think InvokeRepeating() feels like a better fit in these cases.

Dec 24, 2011 at 12:36 PM Bovine
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Nov 28, 2011 at 07:12 PM

Seen: 3416 times

Last Updated: Dec 24, 2011 at 12:36 PM