An ECS limitation I’ve run into:
I’ve optimized my DOTS code so that multiple jobs can write to the same DynamicBuffer in parallel, just with an index offset. There is no chance of collisions. This has been one of our most impactful optimizations, and has also helped simplify our code.
The one big drawback: if you call GetBufferFromEntity() for the same buffer type, from inside two different systems, it will automatically make their jobs dependent on one another.
There’s no way to inform Unity that - no it’s safe - these jobs will definitely write to different indices of these buffers.
The clumsy workaround has been to have a group of systems run before any of my job scheduling systems, which simply call BufferFromEntity() for a given type, and cache the result. Later systems will refer to that cached data instead of calling BufferFromEntity() themselves, and pass it into their jobs. This tricks Unity’s auto-dependency measures.
This works, however - I’m willing to bet that the cost of updating these ‘caching’ systems may be greater than the cost of calling GetBufferFromEntity in each of my job systems. It’s also a clunky way to organize the code.
It would be great if there were a way to inform Unity of this case, and to expect safe parallel writes to a BufferFromEntity from multiple jobs.