Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the cache of the extension framework #3261

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ public TestExtensionTypesV2Attribute(string extensionType, string extensionIdent
internal class MetadataReaderExtensionsHelper
{
private const string TestExtensionTypesAttributeV2 = "Microsoft.VisualStudio.TestPlatform.TestExtensionTypesV2Attribute";
private static readonly ConcurrentDictionary<string, Assembly> assemblyCache = new ConcurrentDictionary<string, Assembly>();
private static readonly ConcurrentDictionary<string, Type[]> assemblyCache = new ConcurrentDictionary<string, Type[]>();
private static readonly Type[] emptyTypeArray = new Type[0];

public Type[] DiscoverTestExtensionTypesV2Attribute(Assembly loadedAssembly, string assemblyFilePath)
=> assemblyCache.GetOrAdd(assemblyFilePath, DiscoverTestExtensionTypesV2AttributeInternal(loadedAssembly, assemblyFilePath));

private Type[] DiscoverTestExtensionTypesV2AttributeInternal(Assembly loadedAssembly, string assemblyFilePath)
{
EqtTrace.Verbose($"MetadataReaderExtensionsHelper: Discovering extensions inside assembly '{loadedAssembly.FullName}' file path '{assemblyFilePath}'");

#if !NETSTANDARD1_3
// Cache assembly, in VS scenario vstest.console is not unloaded so we don't want to load same asm more times.
Assembly assemblyToAnalyze = assemblyCache.GetOrAdd(assemblyFilePath, Assembly.LoadFile(assemblyFilePath));
// We don't cache the load because this method is used by DiscoverTestExtensionTypesV2Attribute that caches the outcome Type[]
Assembly assemblyToAnalyze = Assembly.LoadFile(assemblyFilePath);
#else
Assembly assemblyToAnalyze = loadedAssembly;
#endif
Expand Down