Open thygrrr opened 5 months ago
Improved in #16
No, I was mistaken. This is still alive and kicking, because of how Signature.Contains works (it's not the set contain - it's actually the Linq IEnumerable Contains!)
Only cut it down by ~50%, but that doesn't help with polynomial degree > 2 runtime.
Nah, it was actually resolved, but now the linear o(n) runtime is in Signature.Expand() which takes up half of the cost of creating new archetypes (for CRAZY LARGE signatures, averaging lengths of ~500 Match Expressions ... and only when doing this in a CRAZY complex N:M relation web)
Might need to turn the matching logic around somehow. This is tricky, I'll keep you all posted.
What:
Optimization potential. In very complex N:N or 1:N / O(N²) cases, type expression searches have a massive impact on runtime. While the shown unit test is a THEORETICAL situation, the same might also apply in normal use.
For example it could also be a case for very complex Worlds (i.e. many, many Archetypes) where new Queries would need to search and match many Archetypes, and Archetypes would need to go and update Queries many times (each time a new Archetype is created or disposed).
Filter Expressions would also drastically benefit from this in complex or degenerate Worlds, not just Query Expressions / Match Expressions.
Repro:
e.g. this code is very slow for 500+ relations (that's a LOT of relations on just one Entity, clearly a degenerate case); and it is slow mostly because of the foreach loop in the while loop, which causes to the order of 500² linear set searches of O(~500) elements each, but the cost is also significant (but in the low milliseconds) without this extra loop.
Potential Fix
It would be possible to considerably speed this up by providing a
MatchSignature
property (this is cheap to make) which is the same as theSignature
, but also includes the relevant wildcards. e.g. an Archetype with Entity-Entity Relation components will also contain theMatch<T>
.Entity wildcard for those relations in itsMatchSignature
even though no suchStorage<T>
exists; simply as to match queries withMatch<T>
.Entity in them.In fact, this may be a simple enhancement with profound impact on scalability for (admittedly degenerate!) relationship scenarios.
Possibly a storage list / storage signature / pure signature is easier to build.
This could also speed up matching in general for a infinitesimal, one-time cost during Archetype creation.