Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by byerdelen · Jun 14, 2011 at 08:14 AM · javascriptifstatement

Script Performance Questions

Hello there, the Eldars of Unity Community,

  After a year of coding, now I have enough experience but if you know
  more, you realise you need to know alot more so I have few questions:

  1. I use Javascript and I work on IOS so I need performance, do I have to use C++ in some of the calculations to improve the performance?

  2. I have a lot of coding from previous projects and I want to update them. I know most of the tricks for performance but scripting tricks I am lack of. I have many codes like if(a==b && b==c && c==d && d==e) and it can be changed like if(a==b){if(b==c && c==d && d==e)} so it can be optimised but is this performance optimisation important or is it such a small gain that I do not need to change it?

  3. And it would be easier for me to use if statements alot but if I work on them I can make some shorter with extra effort and smarter coding, I had some ugly coding at past but the performance will change in a way that I would care? Is the if statement very fast?, in this way I mean there are some crazy expensive stuff like FindObject, in compare with those, is if statement expensive in this means or not, like for example is it 10 times cheaper than FindObject or 100 times cheaper? I would calculate my performance needs better if I would have some data, some stuff you cannot learn efficiently from profile, I hope you got what I mean.

Thank you community, sorry for my English and hope for an answer from a person with exact knowledge.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jessy · Jun 14, 2011 at 02:10 PM

  1. You can't script in C++.

  2. That's not an optimization at all. && short-circuits, unlike &.

  3. An if statement is a vital part of coding and you're not going to get rid of it. Write as much code as you need to; if statements are going to have to be a large part of that. if statement are not likely to be bottlenecks.

Comment
Add comment · Show 3 · 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 Bravini · Jun 14, 2011 at 03:00 PM 0
Share

you could script in c++ using plugins (pro only), but that wouldn't be an optimization at all : ]

avatar image Jessy · Jun 14, 2011 at 03:10 PM 0
Share

Writing a plugin isn't scripting.

avatar image byerdelen · Jun 14, 2011 at 03:18 PM 0
Share

Sorry, my mistake, I mean to use C++ directly in Unity ins$$anonymous$$d of Javascript. I heard some loops are much more faster but i couldnt find an exact information.

And according to Jessy, if statements are real fast so I should not think to code more in case of if statements, thats good news, thank you.

avatar image
1

Answer by hellcats · Jun 14, 2011 at 03:28 PM

Understanding and predicting performance isn't easy in general, and a managed environment like Mono makes it even harder. But IMHO the best thing you can do is improve your knowledge of computer hardware and runtime environments. Learn to read assembly language (at least x86), and then get the Mono source code. Look at the IL output from the compiler, then look at how that is JITed into x86 by the Mono runtime. Learn about calling conventions, stack variables vs. heap variables, return results, etc. Get the intel developers guide http://www.intel.com/products/processor/manuals/ . This may sound like a lot, and it is, but this kind of understanding will serve you throughout your entire career.

Comment
Add comment · 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
0

Answer by Bravini · Jun 14, 2011 at 10:47 PM

complementing Jessy and helicats answer, there is a lot of optimization that can be done, and much of it needs further studying and technics. A good place to start is http://unity3d.com/support/documentation/Manual/Optimizing%20Graphics%20Performance.html a tip would be to use getcomponents instead of findGameObjects, but you can find lots of good learning material on the forum or answers from more seasoned developers like Jessy, Erich5h5, Duck, DaveA, Statement, skovacs1, etc that discuss more in depth stuff, just browse their answered questions through the profile and you can learn a lot, I do that once in a while ;)

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

if statement help! 2 Answers

C# Creating a List of If Statements 3 Answers

Script block animations and other scripts 2 Answers

Create file in correct directory 3 Answers

Problems with if statements 2 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