Pretty frequently I see the following two lines one right next to another:
var myJobHandle = myJob.Schedule();
myJobHandle.Complete();
Please correct me if I’m wrong, but isn’t it purposless? We schedule it, it runs in a separate thread and we wait for it just as if we ran it on the same thread. There’s nothing to happen in parallel with, since nothing happens in between Schedule and Complete methods. We say “Make it happen, I’ll wait until it’s done”.
I am not an expert in jobs, but i think the general idea is to schedule early in a frame and complete late in a frame (or distribute over 2 frames if possible) and use dependencies. This will maximize the parallel processing and allow the job system / compiler figure out on how to best utilize the cores.
The above in my understanding is still better then running on the main thread, i.e. if you use parallel for jobs or so…they would run on parallel cores (and finish faster than if executed in the main thread) so basically the same loop would block the main thread for a shorter amount of time.
Plus, when calling Complete, the main thread doesn’t just wait, it starting working on completing the job itself! If your job has dependencies, or is parallel, the main thread can help contribute to getting that work finished.
Partly true, but not quite. The call to Complete calls the entire dependency tree of the job, namely it tells the system: “Find all available resources and do all the work for me at this time”, thus ALL the available Worker threads are included in the work