Before updating to Windows 10 you may need to return your Pro license. More information here

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

121k 80 365 774

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

Can I ask where you have this information from?

Jul 25 at 06:48 PM felixpk

Running benchmarks.

Jul 25 at 06:51 PM Eric5h5
(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: 3450 times

Last Updated: Jul 25 at 06:51 PM