Commit 5aea028
authored
Merge pull request #99 from csprance/relationship-v2
## GECS v7.1.0 — Structural Relationship Queries
**Relationship queries are now as fast as component queries.** No API changes required — your existing `with_relationship()` calls just got dramatically faster.
### What Changed
`with_relationship()` previously worked as a post-filter: after selecting entities by component, it iterated every matched entity and linearly scanned their relationships array. This was O(N×M×K) where N = entities, M = relationships per entity, K = filters.
In v7.1.0, each `(Relation, Target)` pair is baked into the archetype signature. Relationship queries now resolve through the same O(1) archetype bucket lookup that component queries use — no per-entity scanning.
### Performance (Godot 4.6, from benchmarks)
**Exact relationship queries — constant time regardless of entity count:**
| Scale | Relationship Query | Component Query (baseline) |
|------:|-------------------:|---------------------------:|
| 100 | 0.089 ms | 0.060 ms |
| 1,000 | 0.092 ms | 0.061 ms |
| 10,000 | 0.091 ms | 0.137 ms |
Exact `with_relationship([Relationship.new(C_Type.new(), target)])` queries are **flat at ~0.09ms** whether you have 100 or 10,000 entities. That's within noise of a `with_all()` component query.
**Wildcard relationship queries** (`Relationship.new(C_Type.new(), null)`) scale with the number of distinct archetypes matched, not total entities:
| Scale | Wildcard Query |
|------:|---------------:|
| 100 | 0.214 ms |
| 1,000 | 1.941 ms |
| 10,000 | 21.274 ms |
*(This benchmark is worst-case: every entity has a unique target, creating one archetype per entity. Real-world usage with shared targets will be much faster.)*
### What You Need to Do
**Nothing.** The `with_relationship()` API is unchanged. Your existing code benefits automatically.
```gdscript
# This is the same API — it's just fast now
var children = world.query.with_relationship([
Relationship.new(C_ChildOf.new(), parent_entity)
]).execute()
```
Property-based relationship queries continue to work as post-filters (runtime values can't be archetype-keyed):
```gdscript
# Still works — property queries remain post-filter
var high_damage = world.query.with_relationship([
Relationship.new({C_Damage: {"amount": {"_gte": 50}}}, target)
]).execute()
```
### Other Changes
- **Legacy `relationship_entity_index` removed** — the old Dictionary-based index is gone, replaced entirely by the archetype system. Slightly lower memory footprint.
- **Archetype explosion warning** — if you exceed 500 archetypes (possible with many unique relationship targets), a one-time debug warning fires so you can catch unintended combinatorial blowup early.
- **Batch relationship transitions** — `add_relationships([r1, r2, r3])` produces exactly one archetype transition instead of N, keeping bulk operations fast.
- **Freed-target cleanup** — when a target entity is removed from the world, all source relationships pointing to it are automatically cleaned up via the archetype index.
### Test Coverage
313 tests passing, zero regressions. 34 new tests added covering structural relationship storage, signature computation, archetype transitions, query integration, and property query preservation.60 files changed
Lines changed: 12986 additions & 1241 deletions
File tree
- .planning
- codebase
- phases
- 01-archetype-extension
- 02-signature-computation-wildcard-index
- 03-structural-transitions
- 04-query-system-integration
- 05-property-query-preservation-compatibility
- 06-cleanup-performance-validation
- research
- addons
- gdUnit4
- gecs
- debug
- docs
- ecs
- tests
- core
- network
- performance
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
0 commit comments