public static bool SingleRayCast(in CollisionWorld collisionWorld, in RaycastInput raycastInput, out RaycastHit raycastHit)
{
unsafe
{
fixed (CollisionWorld* cw = &collisionWorld)
fixed (RaycastInput* input = &raycastInput)
fixed (RaycastHit* hit = &raycastHit)
{
return RaycastUtils.compiledRaycast.Invoke(cw, input, out *hit);
}
}
}
I used burst FunctionPointer to burst compile this method. It runs faster but still much slower than do a single raycast in traditional physx. Now I am switching back to physx since it is already optimized cpp code and providing more flexibility over ecs physics.
#Single raycast in ecs physics performs bad.
1 messages · Page 1 of 1 (latest)
Cost of bursted function invokation is rather high (similiar to MethodInfo.Invoke()). Most likely most of your time spent on actually invoking it, instead of raycast itself.
I don't even know what's going on here, why is it not running in a job or at least a bursted isystem
I need to run raycast in monobehavior. This is very important if u want ur game to support mod. And I've already used bursted FunctionPointer/job and it's faster than non bursted version. But still much slower than Physx.
I need to run raycast in monobehavior. This is very important if u want ur game to support mod
If game doesn't use MonoBehaviour it's not.
But regardless - your mistake is that you are making raycasts and expecting result right away, which is slowest way possible to have raycasts with both: PhysX or entities.
The best performance is achieved through batching: store all raycast commands. Execute all of them in a loop (in a job) and then export results.
I understand batching is necessary for performance in ecs. But physx can provide both high performance and single cast,and also better flexibility and third party eco.I just want to figure it out why ecs physics can't. Someone replyed me before that it is the function invocation overhead. Also in my test,launching a burst compiled job is more expensive than a functionptr running on mainthread.
The reason I must use mono is due to the source generator eliminate the possible for mod creators to write mod without unity. Now I am only using pathfinding and rukhanka animation for ecs.
Also in my test,launching a burst compiled job is more expensive than a functionptr running on mainthread.
Because you are meant to put all your raycasts into one job, instead of having 1 job per every raycast.
Job has even higher overhead because it involves sending data across different threads. And if you expect result right away - all you do is just waste time by waiting for it to finish.
I know that. Official has already said jobs.run() cause overhead. I just want to test it out if functionptr.invoke is cheaper than starting a job.