[quote=“PublicEnumE, post:10, topic: 800760, username:PublicEnumE”]
Yes, you’ve nailed it. However, for the jobs which might access these buckets later, order may be important. I may need to sort the apples, before they are processed in later jobs.
[/quote]How do you know whether you will/won’t need the apples to be sorted? (Is it dependent on the bucket?) What % of buckets do you estimate will need to be sorted?
[quote]
Some buckets might never be used, after they are populated. In this case, they will still be cleared before the next round of apples is added.
[/quote]What % of the time do you think this will happen?
Also, for the buckets that do get used: how many downstream jobs will need the contents of a specific bucket? Will an individual bucket be read by many jobs, or will each bucket only really be read once?
What I’m wondering about is how much you actually need to be generating these extracted lists per-bucket. Your farmers are basically doing “compute which bucket this apple goes into” - what if, instead of storing the apple in a per-bucket buffer, they just labelled the apple with the result?
You could have the farmers maintain two further pieces of information to help:
- You could have a single shared buffer of bucket counts (i.e. NativeArray of length numBuckets). All entries are zero at the beginning of the frame, and as each farmer computes the result for an apple, they use Interlocked.Increment to increase the counter for the given bucket.
- You could use Chunk component data to store something like a bloom filter of which buckets are used by the apples in this chunk. You can trade off the accuracy of the filter against the memory used per chunk.
After all the farmers have run, you’d have an accurate per-bucket count, as well as the ability to iterate over the apples and find the members of any given bucket (skipping chunks that definitely don’t have apples in the given bucket). I’m assuming that your downstream jobs will be reading the data from the apples anyway, so you’re going to be pulling those chunks into the cache no matter what.
And for the trickiest case, where you need the contents of a bucket to be sorted - I think for that you would still need to allocate a buffer, but doing it after the farmers have completed, you’d know the exact size of the buffer you have to allocate, and you have the chunk filter to help you extract the apples quickly (you could compute a sort key at the same time). Then after extracting the apples, you sort them, ready for downstream jobs to use.