Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback [BurstCompile(OptimizeFor = ...)]

Discussion in '2021.2 Beta' started by Peter77, May 1, 2021.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    From the 2021.2.0a15 changelog:
    • Burst: Added an OptimizeFor option to [BurstCompile], allowing users to say they want fast code, small code, or fastly compiled code.
    • Burst: Assemblies are now allowed to have an [assembly: BurstCompile()] attribute to let users specify compile options that should apply assembly wide (for instance [assembly: BurstCompile(OptimizeFor = OptimizeFor.FastCompilation)]).
    https://unity3d.com/unity/alpha/2021.2.0a15

    Is this in some way bound to the build configuration (debug/release/master, editor)?

    I'm asking because when I iterate in the editor or build a debug Player, I'd prefer
    OptimizeFor.FastCompilation
    . When I build a release/master Player, I'd prefer
    OptimizeFor.Fast
    .

    How would I do this? Do you want us to #ifdef it?
    Code (CSharp):
    1. [BurstCompile(OptimizeFor =
    2. #if DEVELOPMENT_BUILD || UNITY_EDITOR
    3.   OptimizeFor.FastCompilation
    4. #else
    5.   OptimizeFor.Fast
    6. #endif
    7. )]
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    You'd probably use the assembly option for that. So your AssemblyInfo.cs would look like:

    Code (csharp):
    1.  
    2. #if DEVELOPMENT_BUILD || UNITY_EDITOR
    3. [assembly: BurstCompile(OptimizeFor.FastCompilation)]
    4. #else
    5. [assembly: BurstCompile(OptimizeFor.Fast)]
    6. #endif
    7.  
     
    jasonboukheir likes this.
  3. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I don't really care about the compilation times with Burst at all, but I do care about this:
    There totally should be a way to set the default for player (in Burst AOT Settings) and default for editor. You can't expect everyone to put extra boilerplate on code for every place where you use BurstCompile, that's just not cool at all.
     
  4. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Yes, we agree. That's why you should keep `OptimizeFor.Default` for most of the cases, because that will be the one that we will be able to redirect easily to Fast or FastCompilation. If you explicitly set it to something different from Default, we won't be able to change it.
     
    mariandev, mahdi_jeddi and rz_0lento like this.
  5. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Thank you for the response, it did ease my concerns :) Is there any estimate when we could expect the settings for these? eg. for 2021.2 or 2022+?
     
  6. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    The changes are in Burst 1.6, so we should be able to land this as part of Burst 1.6 as it is a kind of usability bug fix. So hopefully in the coming weeks.

    [Edit] Note that Burst 1.6 is still in RC (release candidate) until 2021.2 is final and we will likely have several RC before a final version later this year.
     
    mariandev and rz_0lento like this.
  7. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    265
    It might be more convenient to #if a const value:
    Code (CSharp):
    1. #if DEVELOPMENT_BUILD || UNITY_EDITOR
    2.     public const OptimizeFor OptimizeForDevelopment = OptimizeFor.FastCompilation;
    3. #else
    4.     public const OptimizeFor OptimizeForDevelopment = OptimizeFor.Fast;
    5. #endif
    So you can then just use
    Code (CSharp):
    1. [BurstCompile(OptimizeFor = OptimizeForDevelopment)]
    everywhere. Ultimately though, proper built-in support for player/editor defaults would be far superior.
     
    Ruchir and mariandev like this.