sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.11k stars 1.11k forks source link

_group.GetEntities().AsParallel().ForAll(Execute);这段语句有GC #1077

Open 32haojiufangjia opened 1 year ago

32haojiufangjia commented 1 year ago

先生,你好,我在测试中发现这段语句有GC,请问有办法解决吗

sschmid commented 1 year ago

From Google Translate:

Hello sir, I found during testing that this statement has GC. Is there any way to solve it?

@32haojiufangjia yes, please try

_group.AsEnumerable().AsParallel().ForAll(Execute);
sschmid commented 1 year ago

Fyi, when doing things in parallel, please avoid using generated methods like entity.AddXyz(), entity.ReplaceXyz(), entity.RemoveXyz(), etc, since they result in modifying non-concurrent collections like HashSets, etc. When doing things in parallel I recommend changing the component values directly, e.g.

entity.health.value -= 1;