You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
msgspec.structs.fields() is 20x slower than dataclasses.fields() #963
Hello, I noticed in a project where I have to frequently call msgspec.structs.fields that this method is compared to dataclasses extremely slow (about 20x slower).
changed the title [-]msgspec.structs.fields() is 20x slower thant dataclass.fields()[/-][+]msgspec.structs.fields() is 20x slower than dataclasses.fields()[/+]on Dec 2, 2025
I think it should be possible to speed this up by a lot, as we should have all the information required for this available already within the internal struct state.
Reacted by 叶子, Michael, Etienne Landuré and Jearel Alcantara
Activity
[-]msgspec.structs.fields() is 20x slower thant dataclass.fields()[/-][+]msgspec.structs.fields() is 20x slower than dataclasses.fields()[/+]provinzkraut commentedon Dec 2, 2025
Huh, interesting. I suspect the issue is twofold:
fieldsI think it should be possible to speed this up by a lot, as we should have all the information required for this available already within the internal struct state.
Siyet commentedon Apr 8, 2026
Resolved in the community fork msgspec-arise: issue #7, released in v0.20.2.
Cache structs.fields() result for non-generic structs
Cache structs.fields() result for non-generic structs