Skip to content

Prevent empty registry rows from retaining unused entities - #63

Merged
HexDecimal merged 3 commits into
HexDecimal:mainfrom
antonsoo:fix/prevent-empty-entity-rows
Oct 18, 2026
Merged

HexDecimal merged 3 commits into
HexDecimal:mainfrom
antonsoo:fix/prevent-empty-entity-rows

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Component reads and failed removals can create empty registry rows. Clearing tags also recreates an empty row when checking its loop condition. These rows keep otherwise unused entities alive, and the empty tag rows enter saved games.

Use non-inserting lookups and remove empty rows during cleanup. Live references and incoming relations still retain their entities; query results and the save schema are preserved. This follows the lifetime behavior explained in #9.

Validation:

  • All ten lifetime regressions fail before and pass after. Full tests pass on Python 3.10 and 3.12: 106 passes, with the same two pickle XPASS cases as unchanged main. Mypy and Ruff pass.
  • Across 24 inventory-loop configurations, 4,352 consumed items and their empty saved records are released. Hit-point histories and query results are unchanged; the largest tested save drops from 8,026 to 334 bytes.
  • A save produced on main loads under this repair and its empty item record can be cleared. Repaired saves also load under unchanged main.

Read optional components without allocating sparse-set entries, and avoid creating rows when removals fail. Clear empty component and tag rows so unused entities can be collected while incoming relations and external references retain their existing ownership semantics. Preserve existing query behavior and the save schema.
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (7e852c0) to head (28fa94d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
+ Coverage   99.17%   99.18%   +0.01%     
==========================================
  Files           9        9              
  Lines         966      981      +15     
==========================================
+ Hits          958      973      +15     
  Misses          8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HexDecimal HexDecimal left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixes are good, but this PR seems to showcase an architectural issue with the existing code. It appears that defaultdict is causing more problems than it solves.

I'll approve this with some minor changes.

Comment thread tcod/ecs/entity.py
Comment thread CHANGELOG.md Outdated
@HexDecimal
HexDecimal merged commit 24fcbe1 into HexDecimal:main Oct 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants