Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Batch EntityCommandBuffer

Discussion in 'Entity Component System' started by tertle, Dec 6, 2018.

  1. Jyskal

    Jyskal

    Joined:
    Dec 4, 2014
    Posts:
    28
    @tertle Sweet! I'll check out the code in the morning. One more question; you say

    Isn't the IJobParallelFor you posted doing the same thing? Writing to a new index for every iteration? Wouldn't that give the same performance as a IJobForEachWithEntity? Or are you talking about storing an index on the entity and reading that?

    Code (CSharp):
    1.     [BurstCompile]
    2.     private struct ProduceJob : IJobParallelFor
    3.     {
    4.         public NativeStream.Writer Events;
    5.         public void Execute(int index)
    6.         {
    7.             this.Events.BeginForEachIndex(index);
    8.             for (var i = 0; i < 1000; i++)
    9.             {
    10.                 this.Events.Write(new TestEvent { Value = 1000 + i });
    11.             }
    12.             this.Events.EndForEachIndex();
    13.         }
    14.     }
     
    sngdan likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    If you were using IJobParallelFor per entity then yes it would be the same and just as poor.
    But IJobParallelFor is usually used for other things, like world generation or grouping and it's just the easiest job to demonstrate streams hence it was used.
     
    Jyskal likes this.