Skip to content

Speedup decoding of Enum types - #69

Merged
jcrist merged 1 commit into
masterfrom
faster-strenum
Feb 15, 2022
Merged

Speedup decoding of Enum types#69
jcrist merged 1 commit into
masterfrom
faster-strenum

Conversation

@jcrist

@jcrist jcrist commented Feb 15, 2022

Copy link
Copy Markdown
Member

This optimizes the decoding of Enums, following the same pattern
recently implemented for IntEnum types. A custom hashtable object is
generated once per Enum object and stored on the class as the
__msgspec_lookup__ attribute. The hashtable maps each enum name to its
value, and allows us to lookup the enum values without allocating a
temporary string object and using it to lookup the enum value.

Using this method, I get a 10x speedup on decoding enums. This
implementation will also be used in a follow-up PR for implementing
decoding of Literal string types.

This optimizes the decoding of Enums, following the same pattern
recently implemented for `IntEnum` types. A custom hashtable object is
generated once per Enum object and stored on the class as the
`__msgspec_lookup__` attribute. The hashtable maps each enum name to its
value, and allows us to lookup the enum values without allocating a
temporary string object and using it to lookup the enum value.

Using this method, I get a 10x speedup on decoding enums. This
implementation will also be used in a follow-up PR for implementing
decoding of `Literal` string types.
@jcrist
jcrist merged commit e9e141e into master Feb 15, 2022
@jcrist
jcrist deleted the faster-strenum branch February 15, 2022 02:10
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.

1 participant