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

Improve decoder performance on SQL call #281

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Olegt0rr
Copy link

Pull Request Checklist

  • New code has 100% test coverage
  • (If applicable) The prose documentation has been updated to reflect the changes introduced by this PR
  • (If applicable) The reference documentation has been updated to reflect the changes introduced by this PR
  • Pre-Commit Checks were ran and passed
  • Tests were ran and passed

Description

  • replaced orjson tip with msgspec
  • improved msgspec decode performance

Close Issue(s)

# Create Decoder once and reuse it for all encoding calls,
# to avoid paying setup cost for every call. More info:
# https://jcristharif.com/msgspec/perf-tips.html#reuse-encoders-decoders
_decoder = msgspec.json.Decoder()
Copy link

Choose a reason for hiding this comment

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

Hi - msgspec author here.

The main benefit of creating and reusing a decoder is avoiding processing extra config kwargs on every call to decode, especially the type kwarg. Since you're not passing in any keyword arguments here, using the msgspec.json.decode convenience method should be comparable in performance. No harm in the change you've made here, but also likely no measurable benefit. I'll update our docs page to better clarify when you may want to preallocate a decoder.

Copy link
Author

@Olegt0rr Olegt0rr Aug 12, 2023

Choose a reason for hiding this comment

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

Thanks for clarifying!

The encoder example and the phrase "The same goes for decoding" disoriented me. I understood this in such a way that resources are spent on creating the object itself, so in my projects I created both an encoder and a decoder - then reuse both. And where I know the model in advance, I create an additional decoder.

P.S.: thanks for great product!

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

2 participants