No performance difference between Run, Schedule and ScheduleParallel

Heya, so I’ve created a random movement system for a project:

using Unity.Collections;
using Unity.Core;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

public partial class AgentMoveSystem : SystemBase
{
    protected override void OnUpdate()
    {

        float deltaTime = World.Time.DeltaTime;
        Random rnd = new Random();
        rnd.InitState(49500);


        AgentSpawnSettings settings = EntityManager.GetComponentData<AgentSpawnSettings>(SystemAPI.GetSingletonEntity<AgentSpawnSettings>());

        float3 minPos = settings.MinPos;
        float3 maxPos = settings.MaxPos;

        Entities
            .ForEach((ref MovementAgent agent, ref LocalTransform localTransform) =>
            {

                localTransform.Position =
                new float3(localTransform.Position.x + rnd.NextFloat(), localTransform.Position.y + rnd.NextFloat(), localTransform.Position.z);

                if (localTransform.Position.y < minPos.y) localTransform.Position =
                    new float3(localTransform.Position.x, maxPos.y, localTransform.Position.z);

                if (localTransform.Position.y > maxPos.y) localTransform.Position =
                    new float3(localTransform.Position.x, minPos.y, localTransform.Position.z);

                if (localTransform.Position.x < minPos.x) localTransform.Position =
                    new float3(maxPos.x, localTransform.Position.y, localTransform.Position.z);

                if (localTransform.Position.x > maxPos.x) localTransform.Position =
                    new float3(minPos.x, localTransform.Position.y, localTransform.Position.z);


            }).ScheduleParallel(); //no difference between Run(), Schedule() and ScheduleParallel()
    }
}

The issue is that Run(), Schedule() and ScheduleParallel() all have the same performance. There are 200000 MovementAgent entities with a total of 7 different AgentFlag IComponentData (AgentFlagOne, AgentFlagTwo, AgentFlagThree and so on)

Given that my CPU has 8 physical cores, I’d expect it to be around 80% utilized. But it’s not, and there’s no performance difference between the three different methods.

What am I missing? Appreciate any help.

Make sure that Burst is enabled (Jobs > Burst > Enable Compilation).

Burst is already enabled.

Its usually easier to tell what’s going on by looking at the Profiler → Timeline → Jobs.
Enable flow events in details menu (three dots to the right), start from the system and look bellow into jobs and where they are scheduled.

Maybe they’re completed instantly. Or something else is going on in the background.
You should definitely see differences in performance.
Multitude of which depends on the algorithm you’re trying to parallelize and how effective data layout is.

I had a look at the Profiler data. And it turns out that the worker threads completed before the PlayerLoop was done. So I multithreaded, but without any impact on performance.

2 Likes

Have you tried ISystem and IJobEntity?