Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How much slower is 'slow and safe' vs 'fast but no exceptions'?

Discussion in 'iOS and tvOS' started by techmage, Sep 6, 2012.

  1. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    Anyone done tests on this? Or encounter any instances? I don't see any difference myself...

    And do you know if lets say, you export a Unity project with fast but no exceptions, but then in XCode enable the Objective C exceptions flag, because you have some objective c plugin that uses exceptions. Does this nullify the optimizations from fast but no exceptions in Unity?
     
  2. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    Don't EVER run fast, but no exceptions. No one's code is so clean that it is never going to throw an error. It is much better to be on the safe side because, as you said, the difference too small too see.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I always run fast with no exceptions :) I need the speed :)
     
  4. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    I did and, well, the users didn't like it too much.
     
  5. Skyrise

    Skyrise

    Joined:
    Nov 3, 2005
    Posts:
    158
    I'm also using it, always.
    You just need to be extra careful coding and test a lot, that's it. :)
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's pretty much never a reason to use "slow and safe" aside from development. "Fast but no exceptions" doesn't mean you can't use try/catch blocks, it's referring to Unity exceptions.

    --Eric
     
  7. Guriamo

    Guriamo

    Joined:
    Aug 13, 2011
    Posts:
    55
    for coin gunner i developed with the "slow and safe" mode, but when we optimized it we fixed everything so we could run it at "fast but no exceptions"... was a bit faster actually in the end...
     
  8. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    :confused:
     
  9. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    I haven't used 'Slow and safe' for over two years. That's a ridiculous thing to say. You just need to test and fix your code more, or at the very least don't execute anything unless you've checked to see if what you're about to do is Null first.
     
    gdwilliams84 likes this.
  10. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    Really? S***, Unity should have made that more clear. I've always used slow and safe because I'm always parsing XML and IO stuff and exception handling is essential. Thanks for the tip!
     
  11. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    Wait wait wait, this is true? You can use try catch blocks with exceptions off?
     
  12. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    +1
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use try/catch blocks if you have Unity set to "fast but no exceptions", yes. You can test this quite easily. ;) For example, put this on a GUIText:

    Code (csharp):
    1. function Start () {
    2.     try {
    3.         throw "Yow!";
    4.     }
    5.     catch (err) {
    6.         guiText.text = err.Message;
    7.     }
    8. }
    --Eric
     
  14. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Some facts:
    1. "Fast but no exceptions" has limitation that it will crash if exception is thrown from native code. 100% managed exceptions work fine.
    2. "Fast but no exceptions" also breaks some reflection code. Typically it is the code that tries to discover currently executing stack frame / assembly. This going to be improved with Unity 4.0.
    3. "Fast but no exceptions" improves managed->native calls by about 3x. So calls like transform.position become ~3x faster.
     
    Dean-Kuai and vuplex like this.
  15. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    If we export a unity project with fast but no exceptions, but then in the Xcode project turn on objective-c exceptions, does this negate any performance improvements?
     
  16. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    I thought try/catches were slow?

    For things not in loops though (because I don't know about the performance of testing for null, never bothered to look into it), I usually test to make sure things actually exist..

    Code (csharp):
    1. if (audio  SomeVariable != null) { audio.clip = SomeVariable; audio.Play(); }
    2.  else print ("Audio component and/or variable were null, why? You're an idiot. God I need a drink");
    That sort of thing.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Only if there's an exception.

    --Eric
     
  18. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    I have obviously misspoken. Being a the beginner programmer that I am, I would rather it that my game runs slower than that it crashes constantly on users.
     
  19. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    Code (csharp):
    1. while( timeLeft > 0 )
    2. {
    3.  1. Write code.
    4.  2. Test code.
    5.  3. Fix code.
    6.  
    7.  if (noBugs) break;
    8. }
    9.  
    10. print ("You're finished!")
    11.  
    12.  
    Here's the kicker, the noBugs boolean will never be true.
     
    Last edited: Sep 12, 2012
  20. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    How are we supposed to know where to use these try/catch statements? Seems useless to use these if you have no idea where an exception might occur.

     
  21. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    I'm using Unity 4.5.5 and can run successfully in the Unity Editor with no errors using "Fast but no exceptions". But it never runs on my iPad.

     
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Upgrade to Unity 4.6 latest, since any bugs won't ever be fixed for 4.5.5, assuming that's an issue :)
    Seems as though the ipad problem may well be one of ram consumption. Got any more details?
     
  23. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    My iPad Air is 128MB and the app is a very light board game. It runs perfectly when set to "Slow and Safe".
    But when using "Fast but no exceptions" It crashes. from the console log it looks like networking/wifi is causing it.
     

    Attached Files:

  24. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Just tried it with latest 4.6.1 and I get the exact same thing.
     
  25. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Do you have "Error Pause" enabled in the console? because if it's not, the desktop version will run even though it does have errors.
     
  26. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Do you mean "editor version" instead of "desktop version" ?
     
  27. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  28. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    @hippocoder. Hey man. You were right. I had "Error Pause" disabled and it wasn't stopping on the error. What's more I didn't have show errors enabled and wan't even seeing a serious error. The thing is I knew this stuff but forgot all about it over the months. Thanks for catching that and refreshing my failing memory.
     
  29. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's common :)