Search Unity

Burst: Ahead-of-time compiled delegates / static functions, in builds

Discussion in 'Burst' started by slime73, May 24, 2019.

  1. slime73

    slime73

    Joined:
    May 14, 2017
    Posts:
    107
    I noticed the Burst API has experimental functions (behind a #define) for compiling a delegate at runtime.

    I'm really interested in using something like that, but as far as I can tell those of us who target mobile or console platforms where runtime code generation is disallowed won't be able to make use of Burst outside of Unity's job system.

    Are there plans to extend the Burst API with a way to mark a pure static function for Burst compilation during the build process (or some other way to ahead-of-time compile functions outside of the Job system)?

    In my specific case, our large codebase has a few areas which are already multithreaded using our own systems but would require months of work to switch to the Unity job system (due to extensive use of classes, inheritance, and C# containers). If we were able to leverage Burst to compile specific functions within that code, we could move the hot paths over without nearly as much work, and then slowly move the rest over time.
     
    Last edited: May 24, 2019
    julian-moschuering likes this.
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Does the Run extension for jobs not work with burst? Worth a try if you haven't already.
     
  3. slime73

    slime73

    Joined:
    May 14, 2017
    Posts:
    107
    For my use-case with hot paths inside our own threads, I don't think the overhead of going through Unity's job scheduler would be ideal (if it's even possible) - while Run says it executes immediately on the same thread, it looks like it still does work inside Unity's source aside from just calling the (potentially burst-compiled) function. That said I haven't tried it, so maybe it'd work out fine.
     
  4. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    287
    This is something we are looking at. However, we don't have a specific timeline to share at this time.
     
    Dinamytes and slime73 like this.
  5. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    You can only schedule/complete/run jobs from the main thread.
     
  6. slime73

    slime73

    Joined:
    May 14, 2017
    Posts:
    107
    Indeed. I believe what it says there is a documentation issue, but I haven't tested myself to verify.
     
  7. dstilwagen

    dstilwagen

    Joined:
    Mar 14, 2018
    Posts:
    36
    I saw this in another thread, it talks directly about using burst on main thread functions using Run().
    [Showcase] Pure DOTS UI system (detailed description + feedback): Post 18