Search Unity

Is calling a function inside a job (but the function is defined outside) still burst optimized?

Discussion in 'Burst' started by Mr-Mechanical, Nov 16, 2018.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    If I define a function outside of a job will it still receive the same performance benefits as if it were explicitly written inside Execute() (using Burst compilation)?
     
    vanger1 likes this.
  2. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    I see no reason why calling a method inside a job should break burst compilation.

    See https://docs.unity3d.com/Packages/com.unity.burst@0.2/manual/index.html

    At "Language Support" it says that it does not support "Any methods related to managed objects (e.g array access...etc.)"

    which means, methods which stick to the rules should be fine.

    edit: What brings up another question for me, how do you access the method in a valid way?
     
    Last edited: Nov 16, 2018
    Mr-Mechanical likes this.
  3. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Are we talking about a static Method? For it to be optimized it would be inlined and yes I think that's the only case and way it would work. Inlined static methods with no managed objects.
     
    Mr-Mechanical likes this.
  4. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    vanger1 likes this.
  5. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    The compiler will compile and optimize everything reachable from the Execute() method and will choose to inline or not depending on optimization opportunities. Inline is overall quite aggressive with burst, so many functions will be inlined.
     
    Mr-Mechanical, Antypodish and illinar like this.
  6. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Not explicitly, no. I meant that it is what burst would probably do as @xoofx confirmed. Also, I now realize that not only static methods are reachable from a job.
     
    Mr-Mechanical likes this.