Uh oh!
There was an error while loading. Please reload this page.
Improve perf of CredentialCache.GetCredential - #103714
Conversation
Tagging subscribers to this area: @dotnet/ncl |
/benchmark micro aspnet-perf-lin libs --variable filter=*GetCredential_Uri |
MihaZupan
commented
Jun 19, 2024
usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;usingSystem;usingSystem.Collections.Generic;usingSystem.Net;publicclassCredentialCacheTests{privateconststringUriPrefix="http://name";privateconststringHostPrefix="name";privateconstintPort=80;privateconststringAuthenticationType="authType";privatestaticreadonlyNetworkCredentials_credential=newNetworkCredential();privatereadonlyDictionary<(inturiCount,inthostPortCount),CredentialCache>_caches=new(){{(0,0),CreateCredentialCache(0,0)},{(0,10),CreateCredentialCache(0,10)},{(10,0),CreateCredentialCache(10,0)},{(10,10),CreateCredentialCache(10,10)}};[Benchmark][Arguments("http://notfound",0)][Arguments("http://notfound",10)][Arguments("http://name5",10)]publicNetworkCredentialGetCredential_Uri(stringuriString,inturiCount){CredentialCachecc=_caches[(uriCount:uriCount,hostPortCount:0)];returncc.GetCredential(newUri(uriString),AuthenticationType);}privatestaticCredentialCacheCreateCredentialCache(inturiCount,inthostPortCount){varcc=newCredentialCache();for(inti=0;i<uriCount;i++){Uriuri=newUri(UriPrefix+i.ToString());cc.Add(uri,AuthenticationType,s_credential);}for(inti=0;i<hostPortCount;i++){stringhost=HostPrefix+i.ToString();cc.Add(host,Port,AuthenticationType,s_credential);}returncc;}} |
EgorBot
commented
Jun 19, 2024
Benchmark results on Intel
|
I took a look at why we regressed the one scenario, and it seems that that particular benchmark is measuring a corner case. I locally editted the benchmarks so that the creds in the cache on the same host, but different prefix ( Since the regressed scenario is when we are querying a completely different host, I think the regression is not a big problem. |
rzikm
commented
Jun 24, 2024
// Licensed to the .NET Foundation under one or more agreements.// The .NET Foundation licenses this file to you under the MIT license.// See the LICENSE file in the project root for more information.usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;usingSystem;usingSystem.Collections.Generic;usingSystem.Net;publicclassCredentialCacheTests{privateconststringUriPrefix="http://name/prefix";privateconststringHostPrefix="name";privateconstintPort=80;privateconststringAuthenticationType="authType";privatestaticreadonlyNetworkCredentials_credential=newNetworkCredential();privatereadonlyDictionary<(inturiCount,inthostPortCount),CredentialCache>_caches=newDictionary<(inturiCount,inthostPortCount),CredentialCache>{{(0,0),CreateCredentialCache(0,0)},{(0,10),CreateCredentialCache(0,10)},{(10,0),CreateCredentialCache(10,0)},{(10,10),CreateCredentialCache(10,10)}};[Benchmark][Arguments("http://notfound",0)][Arguments("http://differentHost",10)][Arguments("http://name/prefix5/path",10)][Arguments("http://name/differentPrefix/path",10)][Arguments("http://name/diff/path",10)]publicNetworkCredentialGetCredential_Uri(stringuriString,inturiCount){CredentialCachecc=_caches[(uriCount:uriCount,hostPortCount:0)];returncc.GetCredential(newUri(uriString),AuthenticationType);}privatestaticCredentialCacheCreateCredentialCache(inturiCount,inthostPortCount){varcc=newCredentialCache();for(inti=0;i<uriCount;i++){Uriuri=newUri(UriPrefix+i.ToString()+"/");cc.Add(uri,AuthenticationType,s_credential);}for(inti=0;i<hostPortCount;i++){stringhost=HostPrefix+i.ToString();cc.Add(host,Port,AuthenticationType,s_credential);}returncc;}} |
EgorBot
commented
Jun 24, 2024
Benchmark results on Intel
|
rzikm
commented
Jun 24, 2024
@dotnet/ncl Can I get a review? |
wfurt
left a comment
There was a problem hiding this comment.
LGTM. This can still be noise compared to actual TLS.
Fixes#101991.
Fixes#102281.
Not sure what introduced the original regression, but we can save some time by first checking if candidate credential can have longer prefix match before we start comparing auth schemes and uri, and we can stop early if we find exact match.