<-- back to main (I forgot what a register is)
Your middle management code is overusing just one worker when you have hundreds. Just get it done in one cycle instead of thrashing
// The Synergist Way (Thread Pool Starvation & State Machine Tax)
public async Task<bool> AnyMatchAsync(int[] ids, int targetId)
{
var checks = ids.Select(id => Task.Run(() => id == targetId));
bool[] results = await Task.WhenAll(checks);
return results.Any(r => r);
}
// The Sovereign Engineer Way (AVX2 8-Wide Synchronous SIMD)
// Why schedule 1,000 Task state machines when one YMM register checks 8 IDs per cycle?
public static int MatchTargetMask(ReadOnlySpan<int> ids, int targetId)
{
Vector256<int> needle = Vector256.Create(targetId);
ref int ptr = ref MemoryMarshal.GetReference(ids);
int mask = 0;
for (nuint i = 0; i + 8 <= (nuint)ids.Length; i += 8)
{
Vector256<int> chunk = Vector256.LoadUnsafe(ref ptr, i);
Vector256<int> cmp = Avx2.CompareEqual(chunk, needle);
mask |= Avx2.MoveMask(cmp.AsByte());
}
return mask;
}