Skip to content

Implement a fast enough data component. - #1105

Open
wuke32767 wants to merge 1 commit into
EverestAPI:devfrom
wuke32767:data-component
Open

Implement a fast enough data component.#1105
wuke32767 wants to merge 1 commit into
EverestAPI:devfrom
wuke32767:data-component

Conversation

@wuke32767

Copy link
Copy Markdown
Contributor

I'm not too glad with the current way to attach fields to an entity. DynamicData.For and Component are both slow (to me).

That's why I made this. Why has no one ever done this before?

Advantage

Fast.

Implementation

Now Entity holds a two-dimensional array. It stores all attached fields.

The first dimension stands for the depth of the entity in the inheritance tree.

Users can register their fields to a type, and the second dimension is the unique index they got.

Any fields are attached to only one type (and it's subtype), it can't work as a universal component.

It handles inheritance by depth dimension. Any child entity will be able to access fields attached to the parent entity, naturally.

Any type safe issue is done by hidding the implementation details.

@maddie480-bot maddie480-bot added the 1: review needed This PR needs 2 approvals to be merged (bot-managed) label Apr 6, 2026
@balt-dev

Copy link
Copy Markdown

imo the exception messages here could really use some work

@microlith57 microlith57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

apologies for the late review.

i strongly dislike this; it feels brittle and likely to cause difficult-to-diagnose issues later. perhaps this could be resolved by more thorough safety justification and better error messages, but i am still reluctant to introduce this risk into the codebase without good reason.

note that tools like ConditionalWeakTable are already available; is there a compelling reason why this is insufficient? are you able to measure the performance of this implementation in comparison to CWT? (and, if this is indeed more performant, is that benefit sufficient to justify the risks?)

@maddie480-bot maddie480-bot added 2: changes requested This PR cannot be merged because changes were requested (bot-managed) and removed 1: review needed This PR needs 2 approvals to be merged (bot-managed) labels Aug 6, 2026
@wuke32767

wuke32767 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

a) It's not fragile.

b) As an instance field, it works better with speedrun tool; And as a simple array, it doesn't introduce any DependentHandles and ConcurrentDictionaries.

c) Benchmark shows that

  • CWT read is not too expensive (3 or 7 ns versus my 1 ns) (see here);
  • CWT has gc impact (see here).
  • I have no idea about how to measure the impact to concurrent gc, cpu cache and gameplay, can't say what does it mean to real world program.

d) wait, am i responding to your question or change as requested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2: changes requested This PR cannot be merged because changes were requested (bot-managed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants