Search Unity

Overhead of job.Run

Discussion in 'Entity Component System' started by Weichx, Jun 2, 2020.

  1. Weichx

    Weichx

    Joined:
    Jul 10, 2018
    Posts:
    2
    Hey there, I was wondering if anyone has some insights on how much overhead job.Run has.

    I have some code that is single threaded by necessity and a couple parts of it could benefit greatly from being bursted. I don't care that things won't happen in parallel and I have no dependencies that need to run.The load of the job is quite variable, sometimes it has a lot of input and sometimes just a few elements. I want to run on the main thread and block it until work is completed.

    I'm curious if its worth always calling job.Run or if I'm better off determining some threshold for running the managed version of my code vs the burst job. I assume after burst compiled my job that the overhead is mostly from P/Invoke since we totally skip the scheduler. Is this a valid assumption? Assuming I want to run on the main thread (and block it until work is completed). I've read elsewhere that the threshold for job overhead is somewhere around 0.05ms but I'm unsure if that is true for just scheduling or if it also holds for Run().
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    On my workstation determined by the noise threshold from running performance tests swept across different array sizes:
    Run: 7us
    Schedule: 32 us
    ScheduleParallel: 35 us

    Different systems will have much different results. My suggestion is to account for worst-case.
     
    nico-yeet-studios likes this.