Skip to content

Conversation

james7132
Copy link
Member

Objective

Components has a few functions that are generic but only use with TypeId::of. This forces monomorphization of the TypeId map lookups. Even if it's inlined, this still has a compile time cost.

Solution

Remove unnecessary generic functions that only use TypeId::of in internal ECS metadata types., use the type erased versions instead.

Testing

CI

@james7132 james7132 added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Aug 26, 2025
@Victoronz
Copy link
Contributor

Victoronz commented Aug 26, 2025

I wonder how much of a compile time impact this change has?
These functions could be candidates for the momo technique:
Have the actual functions retain only the generic part plus a call to a private inner function containing the non-generic rest.
(Not saying we need to use the library itself, just the pattern)

Especially for future reference it'd be nice to have a comparison of compile time impact.

@james7132
Copy link
Member Author

I wonder how much of a compile time impact this change has? These functions could be candidates for the momo technique: Have the actual functions retain only the generic part plus a call to a private inner function containing the non-generic rest. (Not saying we need to use the library itself, just the pattern)

They're instantiated with on every Query/System param, and it's unclear to me if that's a one time cost if it's part of codegen for every crate that uses the type in such a position.

The momo technique, at least for these functions, already exist as the type erased versions of the same function.

I agree it's worth evaluating the actual impact it has on compile times. I don't really expect it to move the needle that much, given the worst compile time issues come from our proc macros, and especially the use of all_tuples, but this should at least help.

@IQuick143 IQuick143 added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants