I’m currently learning ECS.
I have a curiosity question: how does Unity choose the number of instance to create for a job?
I’m profiling an IJobEntity on an old pc with 3rd gen i5 4 cores @3.1GHz. The profiling is done with a development build. I have constantly 10000 entities for this job launched with ScheduleParallel() in a system. Batch size is automatic, vsync disabled so I can go above 60 fps.
Most of the time, there are 4 instances (one for each core, including main thread), but sometime, only 3 instances are created and the main thread is waiting, doing nothing. It results in a small spike in term of frame time.
If I remember correctly the Job system (any job system really) doesn’t use 100% of all cores all the time, it’s typically number of physical cores minus one or two. At least the main thread core remains unoccupied - after all it may need to do “main thread stuff”.
The main thread also does the scheduling of jobs and that needs to be very responsive otherwise you’d be stalling all the other CPUs because the main thread couldn’t assign them new work instantly.
That doesn’t seem to be the case here - the main thread should be helping out the worker threads (like in the first screenshot) when JobHandle.Complete() is called.
There’s a mechanism to prevent the main thread from taking on long jobs while waiting, to avoid accidentally taking a big job while waiting on a small job. The mechanism is pretty inconsistent though.