leudz / shipyard

Entity Component System focused on usability and flexibility.
Other
755 stars 46 forks source link

What's the difference between ParIter::Tight and ParIter::Mixed? #165

Closed PudgeKim closed 1 year ago

PudgeKim commented 1 year ago

Hello!

I want to run some_components.modified() in parallel.

I tried writing the code like let ParIter::Tight(par_iter) = components.modified().par_iter() else { unreachable!() }; But it went to the unreachable.

When I tried the code below let ParIter::Mixed(par_iter) = components.modified().par_iter() else { unreachable!() }; It worked.

leudz commented 1 year ago

Hey!

Tight and Mixed are an optimization. To get a Tight iterator the components needs to be all next to each others in memory and the total length of the iterator needs to be known. Mixed can represent all iterators but is slower.

For modified we kind of have all next to each others in memory because it's a single storage but the number of modified components is unknown.

The known/unknown length is important for Producer/UnindexedProducer.