Uh oh!
There was an error while loading. Please reload this page.
Fix perf regressions in Utf8Formatter for integers - #85277
Conversation
When I added UTF8 support to the core numeric types, I also just routed Utf8Formatter to use the public TryFormat API on each type. That, however, regressed some microbenchmarks due to a) going from `StandardFormat` to a `ReadOnlySpan<char>` format and then parsing it back out and b) removing some of the inlining that was there previously. This change puts back into Utf8Formatter.TryFormat the handling of the format and then delegating to the relevant helpers that already exist rather than always going through the public entrypoint (it doesn't do so for 'n', but that's also much rarer to use on a hot path and is also in general more expensive).
ghost
commented
Apr 24, 2023
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsWhen I added UTF8 support to the core numeric types, I also just routed Utf8Formatter to use the public TryFormat API on each type. That, however, regressed some microbenchmarks due to a) going from privatebyte[]_buffer=newbyte[100];[Benchmark][Arguments(42)]publicboolTryFormatInt32_Default(intvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_);[Benchmark][Arguments(123L)]publicboolTryFormatInt64_Default(longvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_);[Benchmark][Arguments(12345UL)]publicboolTryFormatUInt64_Default(ulongvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_);[Benchmark][Arguments(42)]publicboolTryFormatInt32_D2(intvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_,newStandardFormat('D',2));[Benchmark][Arguments(0x1234UL)]publicboolTryFormatUInt64_X4(ulongvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_,newStandardFormat('X',4));[Benchmark][Arguments(long.MinValue)]publicboolTryFormatInt64_X(longvalue)=>Utf8Formatter.TryFormat(value,_buffer,out_,newStandardFormat('X'));
|
Uh oh!
There was an error while loading. Please reload this page.
DrewScoggins
commented
Aug 24, 2023
Still seeing a regression in this test https://pvscmdupload.blob.core.windows.net/reports/allTestHistory/refs/heads/main_x64_ubuntu%2018.04/System.Buffers.Text.Tests.Utf8FormatterTests.FormatterDecimal(value%3a%20123456.789).html Found during 7.0 -> 8.0 perf comparison. |
When I added UTF8 support to the core numeric types, I also just routed Utf8Formatter to use the public TryFormat API on each type. That, however, regressed some microbenchmarks due to a) going from
StandardFormatto aReadOnlySpan<char>format and then parsing it back out and b) removing some of the inlining that was there previously. This change puts back into Utf8Formatter.TryFormat the handling of the format and then delegating to the relevant helpers that already exist rather than always going through the public entrypoint (it doesn't do so for 'n', but that's also much rarer to use on a hot path and is also in general more expensive).