Skip to content

Commit 907ffa7

Browse files
authored
Spike/remove multiple index lookups (#27)
* Updating class multiplexing to get components to remove multiple index lookups * Moved multiplexed ref systems over to use same approach Also upped default entity count for benchmarks
1 parent eb51ee1 commit 907ffa7

4 files changed

Lines changed: 164 additions & 129 deletions

File tree

src/EcsR3.Benchmarks/Benchmarks/BatchVsMultiplexedClassComponentBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected override IEnumerable<IMultiplexedJob<ClassComponent, ClassComponent2,
133133

134134
#endregion
135135

136-
[Params(1000)]
136+
[Params(10000)]
137137
public int EntityCount;
138138

139139
[Params(false, true)]

src/EcsR3.Benchmarks/Benchmarks/BatchVsMultiplexedStructComponentBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected override IEnumerable<IMultiplexedRefJob<StructComponent1Multiplexed, S
134134

135135
#endregion
136136

137-
[Params(1000)]
137+
[Params(10000)]
138138
public int EntityCount;
139139

140140
[Params(false, true)]

src/EcsR3/Systems/Batching/Convention/Multiplexing/MultiplexingBatchedRefSystem.cs

Lines changed: 85 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,23 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T>> compon
5959
ThreadHandler.For(0, componentBatches.Length, i =>
6060
{
6161
var batch = closureBatches.Span[i];
62+
ref var c1 = ref componentPools[batch.Component1Allocation];
63+
6264
foreach (var job in Jobs)
63-
{ job.Process(batch.Entity, ref componentPools[batch.Component1Allocation]); }
65+
{ job.Process(batch.Entity, ref c1); }
6466
});
6567
}
6668

6769
protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T>> componentBatches, T[] componentPools)
6870
{
6971
var batchesSpan = componentBatches.Span;
70-
7172
for(var i=0;i<batchesSpan.Length;i++)
7273
{
7374
var batch = batchesSpan[i];
75+
ref var c1 = ref componentPools[batch.Component1Allocation];
76+
7477
foreach (var job in Jobs)
75-
{ job.Process(batch.Entity, ref componentPools[batch.Component1Allocation]); }
78+
{ job.Process(batch.Entity, ref c1); }
7679
}
7780
}
7881
}
@@ -126,11 +129,11 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2>> c
126129
ThreadHandler.For(0, componentBatches.Length, i =>
127130
{
128131
var batch = closureBatches.Span[i];
132+
ref var c1 = ref components1[batch.Component1Allocation];
133+
ref var c2 = ref components2[batch.Component2Allocation];
134+
129135
foreach (var job in Jobs)
130-
{
131-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
132-
ref components2[batch.Component2Allocation]);
133-
}
136+
{ job.Process(batch.Entity, ref c1, ref c2); }
134137
});
135138
}
136139

@@ -142,11 +145,11 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2>> componentBatch
142145
for(var i=0;i<batchesSpan.Length;i++)
143146
{
144147
var batch = batchesSpan[i];
148+
ref var c1 = ref components1[batch.Component1Allocation];
149+
ref var c2 = ref components2[batch.Component2Allocation];
150+
145151
foreach (var job in Jobs)
146-
{
147-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
148-
ref components2[batch.Component2Allocation]);
149-
}
152+
{ job.Process(batch.Entity, ref c1, ref c2); }
150153
}
151154
}
152155
}
@@ -199,12 +202,13 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2, T3
199202

200203
ThreadHandler.For(0, componentBatches.Length, i =>
201204
{
202-
var batch = scopedComponentBatches.Span[i];
205+
var batch = scopedComponentBatches.Span[i];
206+
ref var c1 = ref components1[batch.Component1Allocation];
207+
ref var c2 = ref components2[batch.Component2Allocation];
208+
ref var c3 = ref components3[batch.Component3Allocation];
209+
203210
foreach (var job in Jobs)
204-
{
205-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
206-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation]);
207-
}
211+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3); }
208212
});
209213
}
210214

@@ -216,11 +220,12 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2, T3>> componentB
216220
for (var i = 0; i < batchesSpan.Length; i++)
217221
{
218222
var batch = batchesSpan[i];
223+
ref var c1 = ref components1[batch.Component1Allocation];
224+
ref var c2 = ref components2[batch.Component2Allocation];
225+
ref var c3 = ref components3[batch.Component3Allocation];
226+
219227
foreach (var job in Jobs)
220-
{
221-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
222-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation]);
223-
}
228+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3); }
224229
}
225230
}
226231
}
@@ -273,12 +278,13 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2, T3
273278
ThreadHandler.For(0, componentBatches.Length, i =>
274279
{
275280
var batch = scopedComponentBatches.Span[i];
281+
ref var c1 = ref components1[batch.Component1Allocation];
282+
ref var c2 = ref components2[batch.Component2Allocation];
283+
ref var c3 = ref components3[batch.Component3Allocation];
284+
ref var c4 = ref components4[batch.Component4Allocation];
285+
276286
foreach (var job in Jobs)
277-
{
278-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
279-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
280-
ref components4[batch.Component4Allocation]);
281-
}
287+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4); }
282288
});
283289
}
284290

@@ -290,12 +296,13 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2, T3, T4>> compon
290296
for(var i=0;i<batchesSpan.Length;i++)
291297
{
292298
var batch = batchesSpan[i];
299+
ref var c1 = ref components1[batch.Component1Allocation];
300+
ref var c2 = ref components2[batch.Component2Allocation];
301+
ref var c3 = ref components3[batch.Component3Allocation];
302+
ref var c4 = ref components4[batch.Component4Allocation];
303+
293304
foreach (var job in Jobs)
294-
{
295-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
296-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
297-
ref components4[batch.Component4Allocation]);
298-
}
305+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4); }
299306
}
300307
}
301308
}
@@ -348,12 +355,14 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2, T3
348355
ThreadHandler.For(0, componentBatches.Length, i =>
349356
{
350357
var batch = scopedComponentBatches.Span[i];
358+
ref var c1 = ref components1[batch.Component1Allocation];
359+
ref var c2 = ref components2[batch.Component2Allocation];
360+
ref var c3 = ref components3[batch.Component3Allocation];
361+
ref var c4 = ref components4[batch.Component4Allocation];
362+
ref var c5 = ref components5[batch.Component5Allocation];
363+
351364
foreach (var job in Jobs)
352-
{
353-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
354-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
355-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation]);
356-
}
365+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5); }
357366
});
358367
}
359368

@@ -365,12 +374,14 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2, T3, T4, T5>> co
365374
for(var i=0;i<batchesSpan.Length;i++)
366375
{
367376
var batch = batchesSpan[i];
377+
ref var c1 = ref components1[batch.Component1Allocation];
378+
ref var c2 = ref components2[batch.Component2Allocation];
379+
ref var c3 = ref components3[batch.Component3Allocation];
380+
ref var c4 = ref components4[batch.Component4Allocation];
381+
ref var c5 = ref components5[batch.Component5Allocation];
382+
368383
foreach (var job in Jobs)
369-
{
370-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
371-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
372-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation]);
373-
}
384+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5); }
374385
}
375386
}
376387
}
@@ -423,13 +434,15 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2, T3
423434
ThreadHandler.For(0, componentBatches.Length, i =>
424435
{
425436
var batch = scopedComponentBatches.Span[i];
437+
ref var c1 = ref components1[batch.Component1Allocation];
438+
ref var c2 = ref components2[batch.Component2Allocation];
439+
ref var c3 = ref components3[batch.Component3Allocation];
440+
ref var c4 = ref components4[batch.Component4Allocation];
441+
ref var c5 = ref components5[batch.Component5Allocation];
442+
ref var c6 = ref components6[batch.Component6Allocation];
443+
426444
foreach (var job in Jobs)
427-
{
428-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
429-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
430-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation],
431-
ref components6[batch.Component6Allocation]);
432-
}
445+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5, ref c6); }
433446
});
434447
}
435448

@@ -441,13 +454,15 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2, T3, T4, T5, T6>
441454
for(var i=0;i<batchesSpan.Length;i++)
442455
{
443456
var batch = batchesSpan[i];
457+
ref var c1 = ref components1[batch.Component1Allocation];
458+
ref var c2 = ref components2[batch.Component2Allocation];
459+
ref var c3 = ref components3[batch.Component3Allocation];
460+
ref var c4 = ref components4[batch.Component4Allocation];
461+
ref var c5 = ref components5[batch.Component5Allocation];
462+
ref var c6 = ref components6[batch.Component6Allocation];
463+
444464
foreach (var job in Jobs)
445-
{
446-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
447-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
448-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation],
449-
ref components6[batch.Component6Allocation]);
450-
}
465+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5, ref c6); }
451466
}
452467
}
453468
}
@@ -500,13 +515,16 @@ protected void ProcessJobsMultithreaded(ReadOnlyMemory<ComponentBatch<T1, T2, T3
500515
ThreadHandler.For(0, componentBatches.Length, i =>
501516
{
502517
var batch = scopedComponentBatches.Span[i];
518+
ref var c1 = ref components1[batch.Component1Allocation];
519+
ref var c2 = ref components2[batch.Component2Allocation];
520+
ref var c3 = ref components3[batch.Component3Allocation];
521+
ref var c4 = ref components4[batch.Component4Allocation];
522+
ref var c5 = ref components5[batch.Component5Allocation];
523+
ref var c6 = ref components6[batch.Component6Allocation];
524+
ref var c7 = ref components7[batch.Component7Allocation];
525+
503526
foreach (var job in Jobs)
504-
{
505-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
506-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
507-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation],
508-
ref components6[batch.Component6Allocation], ref components7[batch.Component7Allocation]);
509-
}
527+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5, ref c6, ref c7); }
510528
});
511529
}
512530

@@ -518,13 +536,16 @@ protected void ProcessJobs(ReadOnlyMemory<ComponentBatch<T1, T2, T3, T4, T5, T6,
518536
for(var i=0;i<batchesSpan.Length;i++)
519537
{
520538
var batch = batchesSpan[i];
539+
ref var c1 = ref components1[batch.Component1Allocation];
540+
ref var c2 = ref components2[batch.Component2Allocation];
541+
ref var c3 = ref components3[batch.Component3Allocation];
542+
ref var c4 = ref components4[batch.Component4Allocation];
543+
ref var c5 = ref components5[batch.Component5Allocation];
544+
ref var c6 = ref components6[batch.Component6Allocation];
545+
ref var c7 = ref components7[batch.Component7Allocation];
546+
521547
foreach (var job in Jobs)
522-
{
523-
job.Process(batch.Entity, ref components1[batch.Component1Allocation],
524-
ref components2[batch.Component2Allocation], ref components3[batch.Component3Allocation],
525-
ref components4[batch.Component4Allocation], ref components5[batch.Component5Allocation],
526-
ref components6[batch.Component6Allocation], ref components7[batch.Component7Allocation]);
527-
}
548+
{ job.Process(batch.Entity, ref c1, ref c2, ref c3, ref c4, ref c5, ref c6, ref c7); }
528549
}
529550
}
530551
}

0 commit comments

Comments
 (0)