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

Implement zero-alloc support for reading field names #123

Merged
merged 3 commits into from Apr 16, 2023
Merged

Conversation

agocke
Copy link
Collaborator

@agocke agocke commented Apr 16, 2023

Currently the custom type visitor just deserializes field names as strings, which allocates a new System.String for each field. However, the API supports passing through a ReadOnlySpan for UTF8 strings. This change should provide support using the ROS in the normal path and avoid allocation.

Before:

Method Mean Error StdDev Gen0 Gen1 Allocated
SerdeJson 1,983.3 ns 24.13 ns 22.57 ns 0.2708 - 1712 B

After:

Method Mean Error StdDev Gen0 Gen1 Allocated
SerdeJson 1,729.5 ns 16.44 ns 15.38 ns 0.1831 - 1152 B

Currently the custom type visitor just deserializes field names as
strings, which allocates a new System.String for each field. However, the
API supports passing through a ReadOnlySpan<byte> for UTF8 strings. This change
should provide support using the ROS<byte> in the normal path and avoid allocation.
@agocke agocke marked this pull request as ready for review April 16, 2023 03:15
@agocke agocke merged commit 1585c23 into main Apr 16, 2023
1 check passed
@agocke agocke deleted the no-string-alloc branch April 16, 2023 03:16
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