Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mono performance : same tips when working with visual studio?

Discussion in 'Scripting' started by Casto, Mar 25, 2014.

  1. Casto

    Casto

    Joined:
    Aug 14, 2013
    Posts:
    44
    Hi,

    I've being developing with Unity for over a year and I feel more and more concerned by the performance of my scripts in general. I've already read excellent articles about performance issues with c# .NET and I'm now considering buying what appears to be an excellent book about this topic.
    But now I'm wondering if all advices, good practices, performance tips (including micro optimizations) are always significant for Mono? What I mean is that mono hasn't the same compiler as Visual Studio, and won't produce the same bytecode. So how do I know if all theses tips (which are given for .NET) are true for mono too?

    What do you think?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    You'll need to give more specific examples for us to give you a real answer.

    However, in my experience the vast majority of optimizations are not heavily dependent on the precise compiler you're using. Caching a reference is pretty much always faster than searching for it repeatedly, etc. Even ones that seem compiler-dependent are probably more or less applicable even across compilers; for example, using an algorithm with a square root is just going to be slower than using an algorithm that squares the thing you're comparing it to instead (to use the classic .magnitude vs .sqrMagnitude example) - it's just how MUCH faster that is going to change somewhat depending on the compiler.
     
  3. Casto

    Casto

    Joined:
    Aug 14, 2013
    Posts:
    44
    Thanks for your reply,

    What you say makes sense. That's more or less what I was thinking.
    There are tons of questions to ask actually... For example does Mono compiler inline some methods like VS does?

    I think I'm gonna buy this book because as you say, 99% of its content will be good for mono too (at least I hope): http://www.amazon.com/gp/aw/d/1430244585/ref=mw_dp_mdsc?dsc=1&vs=1

    Thanks
     
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    you know for sure when you do the profiling of your "optimization" and compare it to the result of your unoptimized code. you cannot simply optimize something and then forget about it. you must always ensure that your optimization actually improves performance. if it does not (significantly) revert to the previous code.