• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Fattie · Oct 10, 2013 at 08:34 AM · performanceupdate

Few versus many Update() routines?

I've often wondered .. is there any advantage to minimising your Update() routines?

Say you have 100 scripts and 20 use Update(). Compare to "centralising" so that you have only one or two scripts with Update().

Performance-wise - with the specific issue of Update() calls in the Unity milieu - is there any difference?

Is this something everyone knows about other than me as usual? Any thoughts? Cheers!

Comment
karlhulme

People who like this

1 Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KiraSensei · Oct 10, 2013 at 09:17 AM 0
Share

I asked a question close to this one some time ago.

here it is.

avatar image pako · Oct 10, 2013 at 09:21 AM 0
Share

Hi Fattie,

I believe that the fewer methods that get called the better the performance, because every method that gets called carries some overhead. This is much more so, with the Update() method, because it gets called every frame (as I'm sure everybody in the Unity community knows). So, the overhead inherent on method calling occurs in every frame.

So, if it were possible to include the 1,000 lines of code originally located in each of 10 Update() methods, to 1 Update() method containing 10,000 lines of code, there would be an overall performance gain.

However, I can see 2 issues with this:

a. In order to "centralize" the code in a single Update, it would most likely be necessary to create references to decentralized code. This would probably create a performance loss that would be greater than the performance gain from centralizing.

b. If there is plenty of code inside the original Update() methods, then the majority of the workload would be in executing the code, and the performance hit for calling this Update() method would be insignificant.

Bottom of the Line: I would be concerned with centralizing Update() methods, only if I had a large number of them, with each containing only very few lines of "light" code.

avatar image Fattie pako · Oct 10, 2013 at 09:57 AM 0
Share

Hi @pako, you're just re-stating the question.

"because every method that gets called carries some overhead", yes, obviously, the question is: what's the overhead involved with Update callbacks in the overall unity - mono - monobehaviour - component milieu. (just branching to a routine is nothing)

"the performance hit for calling this Update() method..." is unknown, it's what I'm asking

avatar image Fattie · Oct 10, 2013 at 09:31 AM 0
Share

need actual facts on this guys.

avatar image pako · Oct 10, 2013 at 09:43 AM 0
Share

If you google something like "c# method call performance" you'll get some interesting links. Basically, it all comes down to testing it yourself if you want actual facts. The Stopwatch Class is useful for this:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

avatar image Fattie · Oct 10, 2013 at 09:58 AM 0
Share

hey pako, naturally I could do the work myself - but that's no fun. better to ask here :) it's difficult to believe this isn't a well-known topic that has been well-explored

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Graham-Dunnett · Oct 10, 2013 at 10:49 AM

The cost of calling multiple Update() functions is completely lost in the noise. Unity has a list of objects with Update() functions and calls them in turn. (Or the order you specify.)

Comment
Fattie
karlhulme

People who like this

2 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Oct 10, 2013 at 11:28 AM 0
Share

"completely lost in the noise" Magnificent - thanks a million for that, GD!!!

avatar image $$anonymous$$ · Feb 05, 2018 at 12:32 PM 0
Share

"is completely lost in the noise" - what does that mean?

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using coroutines for move objects - performance. 1 Answer

performance impact of destination update (navmeshagent) 0 Answers

Update with bool flag or script enabled/disabled? 2 Answers

Performance Optimization ~Function Update: Loop or Once ? 5 Answers

Update functions and performance 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges