You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue impacts scenarios of large token cache, which is common for client credential flows (300k+ tokens). MSAL copies access tokens from memory into a list several times, which is a perf impact (TBD - numbers)
Technical details:
InMemoryTokenCacheAccessor.GetAllAccessTokens() iterates through the whole AT collection and returns a List. When TokenCacheNotificationArgs.HasTokens property is set, it calls TokenCache.ITokenCacheInternal.HasTokensNoLocks() which eventually calls InMemoryTokenCacheAccessor.GetAllAccessTokens(). CacheSessionManager.RefreshCacheForReadOperationsAsync sets that property twice.
So the AT dictionary ends up being iterated 3 times for a read, 2 times for a save. This can have a perf hit when cache has a large number of tokens.
Possible enhancement: Update GetAllAccessTokens() to not create a list or reduce the number of calls to GetAllAccessTokens().
bgavrilMS
changed the title
[Feature Request] Improve calling GetAllAccessTokens method in internal cache
[Perf] Access tokens are listed too many times in AcquireTokenSilent / AcquireTokenForClient
Nov 18, 2020
This issue impacts scenarios of large token cache, which is common for client credential flows (300k+ tokens). MSAL copies access tokens from memory into a list several times, which is a perf impact (TBD - numbers)
Technical details:
InMemoryTokenCacheAccessor.GetAllAccessTokens()
iterates through the whole AT collection and returns aList
. WhenTokenCacheNotificationArgs.HasTokens
property is set, it callsTokenCache.ITokenCacheInternal.HasTokensNoLocks()
which eventually callsInMemoryTokenCacheAccessor.GetAllAccessTokens()
.CacheSessionManager.RefreshCacheForReadOperationsAsync
sets that property twice.So the AT dictionary ends up being iterated 3 times for a read, 2 times for a save. This can have a perf hit when cache has a large number of tokens.
Possible enhancement: Update
GetAllAccessTokens()
to not create a list or reduce the number of calls toGetAllAccessTokens()
.microsoft-authentication-library-for-dotnet/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/InMemoryTokenCacheAccessor.cs
Lines 155 to 165 in 24cb466
microsoft-authentication-library-for-dotnet/src/client/Microsoft.Identity.Client/TokenCache.ITokenCacheInternal.cs
Lines 818 to 822 in 24cb466
microsoft-authentication-library-for-dotnet/src/client/Microsoft.Identity.Client/Cache/CacheSessionManager.cs
Lines 106 to 129 in 24cb466
The text was updated successfully, but these errors were encountered: