#bevy_mod_index
18 messages ยท Page 1 of 1 (latest)
So make the pitch: why should we migrate to bevy_mod_index from an already working "Hashmap in a resource" solution? ๐
Right now the I think the big plus is that Indexes refresh themselves when you use them, so you don't need to maintain a system to update them with the latest data, and you will see changes from earlier in the same frame.
๐ Appealing! Right now I'm just indexing structures, so I'm doing it with Commands and it's working pretty well!
They don't exactly change their position very quickly
@coarse canopy have you considered using a bloom filter? Seems it could be nice for very large entity counts, can narrow down for fairly cheap the set of things to check, especially for 4/8-bytes indices.
Bloom filters are one of those things that sound really cool when you learn about them but in practice the amount of scenarios in which they truly make sense is extremely rare and niche. Hashing is kind of expensive and doing a lot of that to only get a chance of a right answer while using a lot of memory is generally not worth it in common use.
I specifically mentioned "4/8 bytes indices", a simple PRNG would be a good hash, furthermore, bloom filters are specifically about saving memory, you don't have to store the preimage and you can get away with a 64 or 128 bits (bits, not bytes) array.
I thought this was a surprisingly but promising use-case for a bloom filter
Iirc, I computed a 95% hit rate on a few thousand entries for a 128 bits bloom filter
The way you do it is:
- you run the PRNG on your index value
- Pick the first 7 bits as the index in the 128 bit array to enable
- Pick the next 7 bits for the second index to enable
That's the bit array to compare against
Now you have the base array to compare against, it's the same process to do "contains" check. This can save a lot of computation depending on how sparse your indexed lookups are.
As you can see, I thought about this a bit.
Interesting, I hadn't heard of bloom filters before. I'm not sure how helpful they would be though. My current assumption is that updating the index is the bottleneck, not the lookup itself.
From what I've just read, it seems like they are best at when the real lookup is quite slow (like reading from disk) and you can't keep everything in memory, but I would already need to keep the actual source of truth in memory anyway
Well it might hypothetically still increase cache hit rates on negative queries. But I agree that updating the index is probably going to dwarf that in most scenarios.
Hi, I am currently looking into bevy_mod_index and was wondering: Is it possible to specify an index that only works on entities with a specific set of components? What I mean is this: I am using marker components which I suffix with "Tag" and for the example's sake let's say I also have an Id component. Now what I would like to do is create a way to retrieve all entities with FooTag by the value of the Id component. And at the same time, I would also want an index for BarTag entities. Ideally, this would also support some combination similar to queries where I could specify the indexed entities need component A but cannot have component B, etc. I hope this makes clear what I am trying to achieve. Happy to elaborate further if necessary. Is this already possible?
This is not yet possible, but it is on my todo list.
For now, I would recommend making a single index over all Ids and using the Entity returned by lookup with Query::get to see if the actually has the right tag
Thanks for the quick reply. After playing around with different solutions I am for now going with a separate Id component for each type of entity. It's not as elegant but seems like the best solution for my current goals.
I'm doing some experimentation with this crate, I didn't test it to replace resources yet, I only used it in a very simple use case to try out, where I replace a query with a lot of checking by a index lookup. However, I noticed up to 20x slow down in some benchmarks I was doing.
Am I doing something wrong? (maybe the scenario I picked doesn't fit this well).
Or is that expected?