Skip to content

Avoid allocation in deserialize to i64 #84

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

Merged
merged 4 commits into from
Jun 2, 2025

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Jun 2, 2025

This is another item taken out of #70.

The current implementation of deserialize_string_to_i64 first deserializes a JSON value to a String before attempting to parse it as an i64 value. This requires an intermediate allocation for the string value because it's owned by deserialize_string_to_i64. Calling str::parse works on a reference too though, so writing a proper serde visitor with the ability to handle ephemeral strings improves performance slightly. It also ensures that the method works for non-JSON deserializers (such as BSON).

@simolus3 simolus3 requested a review from rkistner June 2, 2025 15:12
@simolus3 simolus3 merged commit 08f59fa into main Jun 2, 2025
21 checks passed
@simolus3 simolus3 deleted the avoid-allocation-in-deserialize-to-i64 branch June 2, 2025 15:26
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.

2 participants