Smart Job Scheduling

I’m trying to improve job scheduling as well as memory usage by reusing most of my in between buffer jobs. for that i keep DataThreadCount numbers of my in between buffer jobs and reuse them and avoid error by saving the previous thread JobHandle and use it as dependency for the next one.

better explained with some pseudo code:

            // params are: data it needs, buffer pool index to use, previous job handle that uses the buffer pool index as dependsOn
            var handle = DoJobStuff(inputData, threadIndex, threadHandles[threadIndex]);
            threadHandles[threadIndex++] = handle;
            // threadCount= math.max((int)(JobsUtility.JobWorkerCount * threadsUsage), 1);
            threadIndex %= threadCount;

           //... inside DoJobStuff()
           var handle = job1.Schedule(dependsOn); // uses pooled buffers for in between step1
           handle = job2.Schedule(handle); // more pooled buffers for step2
           handle = job3.Schdule(handle); // output, uses new, non pooled, output buffers
           return handle;

however this results in this chaos

instead of what i am expecting like something like this

is there a better way to group those jobs together that doesn’t create almost a synchronous pattern

Have you solved this?

same here, despite disabling safetycheck and jobdebugger(unity conference advice), my worker threads looks like a broken puzzle.

OH i just happen to change the scripting backend and Api compatibility lvl to this:
6933981--814368--upload_2021-3-14_19-41-0.png

the result is much better since then:


still not perfect but much better

EDIT:
By curiosity i go back to the de default setting:
6933981--814380--upload_2021-3-14_19-48-22.png
and saw again my workers turn into a messy puzzle:

SO, one part of the solution lie here:


changes:
mono → IL2CPP
.NET Standard 2.0 → .NET 4.x

BUT still there is thoses big gaps between job, who i guess shouldn’t be there.

Did you try .net standard and il2cpp?
I really think you should stick with standard instead framework.

Anyway IL2CPP is quite a faster than mono, in particular with floating point math

Did some bad surprises await me with the “new” framework?
i will try without it, thanks for the advice

Standard vs core vs framework is very confusing but unless you need specific access to one of the few libraries that only support .net framework 4 then I suggest sticking with standard.

https://docs.microsoft.com/en-us/dotnet/standard/net-standard

for me it got a lot better when the jobs take longer to complete (larger chunks of work) but i can’t always do that