Skip to content

Several performance improvements to serialization #32

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SabrinaJewson
Copy link

@SabrinaJewson SabrinaJewson commented Jan 8, 2022

  • The itoa and ryu crates (the same crates serde_json uses) avoid allocating anything when serializing integers and floats.
  • By switching the code to work on bytes instead of &strs, expensive Unicode handling can be avoided (e.g. str::bytes is a lot cheaper to run than str::chars).
  • We can copy serde_json and start serialization with a capacity of 128, to avoid excessive reallocations.
  • Since we use bytes now we might as well expose ser::to_bytes.
  • Edit: I came back to this and overrode Serializer::collect_str because we can provide a more efficient implementation than the default.

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