microsoft / artifacts-credprovider

The Azure Artifacts Credential Provider enables dotnet, NuGet.exe, and MSBuild to interactively acquire credentials for Azure Artifacts feeds.
MIT License
782 stars 705 forks source link

Use System.Text.Json for json (de)serialization #393

Closed JohnSchmeichel closed 1 year ago

JohnSchmeichel commented 1 year ago

The serialization and deserialization cost for Newtonsoft.Json causes significant slowdowns, especially in the cases of cached tokens where the process is not long lived. Swapping in System.Text.Json improves startup times.

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.23430.1000) Intel Xeon CPU E5-1650 v3 3.50GHz, 1 CPU, 12 logical and 6 physical cores .NET SDK=8.0.100-preview.2.23157.25 [Host] : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2 Job-KGDGIP : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2

System.Text.Json:

IterationCount=1 RunStrategy=ColdStart WarmupCount=0

Method Mean Error Allocated
CachedSessionToken 460.5 ms NA 519.3 KB
CachedMsalToken 1,737.0 ms NA 1979.85 KB

IterationCount=3 RunStrategy=ColdStart WarmupCount=0

Method Mean Error StdDev Median Allocated
CachedSessionToken 254.9 ms 2,957.7 ms 162.1 ms 163.6 ms 481.46 KB
CachedMsalToken 967.8 ms 12,418.7 ms 680.7 ms 586.7 ms 1889.65 KB

Newtonsoft.Json:

IterationCount=1 RunStrategy=ColdStart WarmupCount=0

Method Mean Error Allocated
CachedSessionToken 586.9 ms NA 559.24 KB
CachedMsalToken 2,074.3 ms NA 2142 KB

IterationCount=3 RunStrategy=ColdStart WarmupCount=0

Method Mean Error StdDev Median Allocated
CachedSessionToken 343.7 ms 5,947.7 ms 326.0 ms 162.1 ms 519.8 KB
CachedMsalToken 1,277.7 ms 20,494.6 ms 1,123.4 ms 660.3 ms 2064.86 KB
JohnSchmeichel commented 1 year ago

/azp where

azure-pipelines[bot] commented 1 year ago
Azure DevOps orgs getting events for this repository: