JsonNumber uses string as a backing field, which requires unnecessarily expensive conversions.
Alternatives to consider:
Additionally, in JsonNumber.SetFormattedValue:
JsonWriterHelper.ValidateNumber(Encoding.UTF8.GetBytes(value).AsSpan());
unnecessarily allocates a byte[]. We can try and avoid that (and the solution depends on how perf critical this is).
_Originally posted by @ahsonkhan in dotnet/corefx#39917 (comment) and dotnet/corefx#39917 (comment)
JsonNumberusesstringas a backing field, which requires unnecessarily expensive conversions.Alternatives to consider:
Additionally, in
JsonNumber.SetFormattedValue:unnecessarily allocates a
byte[]. We can try and avoid that (and the solution depends on how perf critical this is).JsonWriterHelper.ToUtf8similar to:https://github.com/dotnet/corefx/blob/97d5957fc71853961082e22873d926269b291b92/src/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Helpers.cs#L207-L214
_Originally posted by @ahsonkhan in dotnet/corefx#39917 (comment) and dotnet/corefx#39917 (comment)