Improve DateTime{Offset} "r" and "o" formatting performance (#17092)
authorStephen Toub <stoub@microsoft.com>
Wed, 21 Mar 2018 21:35:56 +0000 (17:35 -0400)
committerGitHub <noreply@github.com>
Wed, 21 Mar 2018 21:35:56 +0000 (17:35 -0400)
commit06be68e39634b0fa6490a2d500912e83dc78ed1e
tree295f45ea41070f0d9d7ec1ed824f762eade47c09
parentb82063e24b34c875891916a1bbc01728b9022bf3
Improve DateTime{Offset} "r" and "o" formatting performance (#17092)

Two main changes:
1. Rewrote the formatting to use span, only to then discover that we already had almost exactly the same implementation in Utf8Formatter.  As that one had some extra optimizations around JIT behaviors, I ported that over instead.
2. Avoided [ThreadStatic] lookups unless necessary.

ToString/TryFormat for "o"/"O" improve by ~2.5x.

ToString/TryFormat for "r"/"R" improve by ~3x.
src/mscorlib/shared/System/DateTime.cs
src/mscorlib/shared/System/DateTimeOffset.cs
src/mscorlib/shared/System/Globalization/DateTimeFormat.cs