[release/9.0] Mitigate JsonObject performance regression. by github-actions[bot] · Pull Request #108014 · dotnet/runtime

Backport of #107944 to release/9.0

/cc @eiriktsarpalis

Customer Impact

  • Customer reported
  • Found internally

In .NET 9 the JsonObject implementation was retargeted to the newly published System.Collections.Generic.OrderedDictionary collection, replacing a bespoke collection implementation. The change left a suboptimal implementation in its indexer, resulting in a ~70% performance regression when constructing new objects.

Regression

  • Yes
  • No

Regressed by #103645.

Testing

Added relevant benchmarks to dotnet/performance.

Risk

Medium. The fix involves using different APIs on the brand new OrderedDictionary type so there is risk that this might surface other undiscovered bugs.