I’ve been optimizing a system and I’ve found that there seems to be a dramatic performance difference with filtering using IJobProcessComponentData and ComponentGroup/ComponentSystem. I am not sure why. I am using 2018.3.0f2 and testing on an early 2014 MacBook Air. This wouldn’t normally be an issue as I could just use IJobProcessComponentData, but unfortunately, IJobProcessComponentData no longer fits all of my use cases. Thanks, any help would be appreciated.
IJobProcessComponentData might have a tiny bit more overhead than manual chunk iteration, but not significantly noticeable to warrant not using it.
Some source code could help.
I added a new system to my application and found that the performance hit was much higher than I expected. So I removed all the code but filtering bits. After removing everything but the barebones my ComponentSystem still caused performance issues. What’s weird is when I switched to the less explicit IJobProcessComponentData it was for some reason way faster than ComponentSystem in my testing.
Adding this empty system causes absolutely no performance trouble (80 fps)
[UpdateAfter(typeof(PreviousSystem))]
public class OKSystem : JobComponentSystem
{
[BurstCompile]
struct Job : IJobProcessComponentData<SomeComponent>
{
public void Execute([ReadOnly] ref SomeComponent someComponent)
{
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new Job();
return job.Schedule(this, inputDeps);
}
}
But for some reason using this ComponentSystem makes my fps go from 80 to 40 in standalone build
[UpdateAfter(typeof(PreviousSystem))]
public class TroubledSystem : ComponentSystem
{
ComponentGroup group;
protected override void OnCreateManager()
{
group = GetComponentGroup(ComponentType.ReadOnly(typeof(SomeComponent)));
}
protected override void OnUpdate()
{
}
}
I plan to test on different hardware and os soon. Maybe this issue is platform specific.
IJobProcessComponentData is multi threaded.
OnUpdate is single threaded.
If that matter in your case?
You’re comparing two things that can’t really be compared here.
You can use IJobProcessComponentData in ComponentSystem and ComponentGroup in JobComponentSystem.
Why are you even switching to ComponentSystem?
Thank you guys . This has completely and utterly fixed my problem.
For some reason, I always thought ComponentSystem and ComponentGroup had something to do with each other. Thanks for clearing that up, I really appreciate it. Is it just that ComponentSystem is on main thread? What is ComponentSystem used for?
ComponentSystem is mainthread-only. It’s mostly for hybrid code that needs to work on the main thread.
It can act as a sync point like a BarrierSystem, as it even has it’s own EntityCommandBuffer member: PostUpdateCommands
.
To put it as simple as possible
JobComponentSystem is for work that uses jobs
ComponentSystem is for work that doesn’t use jobs
This is obviously an oversimplify, you can still use jobs in component system you just have to finish them on the spot.
It’s usually used for hybrid code or syncing to stuff that needs the main thread (eg. applying a mesh etc.)
-edit- beaten by a second.