Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce module state lookup in hot paths #84

Merged
merged 1 commit into from Mar 9, 2022

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Mar 9, 2022

Looking up the module state is generally pretty quick, but if done in a
hot path (e.g. encoding/decoding when not raising an exception) it can
add up. We now store a reference to the module state on the encoder,
which reduces the cost of serializing enum.Enum objects by 20-30%, and
negligibly improves a few other encode paths. We also micro-optimize a
few other places where we access the module state. This could be done on
the decoder as well, but (almost) all access in the decoder is for
raising errors and so wouldn't improve performance in common hot paths.

Looking up the module state is generally pretty quick, but if done in a
hot path (e.g. encoding/decoding when not raising an exception) it can
add up. We now store a reference to the module state on the encoder,
which reduces the cost of serializing `enum.Enum` objects by 20-30%, and
negligibly improves a few other encode paths. We also micro-optimize a
few other places where we access the module state. This could be done on
the decoder as well, but (almost) all access in the decoder is for
raising errors and so wouldn't improve performance in common hot paths.
@jcrist jcrist merged commit 2dcba0f into master Mar 9, 2022
@jcrist jcrist deleted the reduce-module-state-access branch March 9, 2022 03:48
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.

None yet

1 participant