Permalink
Browse files

Cache assembly lookup results - improves performance (especially for …

…failed lookups)
  • Loading branch information...
1 parent 6c94092 commit a318ce67bed3482bae7ea13a92ab124c315fe7db @dgrunwald dgrunwald committed Jun 17, 2011
Showing with 12 additions and 1 deletion.
  1. +4 −0 ILSpy/AssemblyList.cs
  2. +8 −1 ILSpy/LoadedAssembly.cs
View
@@ -41,6 +41,8 @@ public sealed class AssemblyList
/// <summary>Dirty flag, used to mark modifications so that the list is saved later</summary>
bool dirty;
+ internal readonly ConcurrentDictionary<string, LoadedAssembly> assemblyLookupCache = new ConcurrentDictionary<string, LoadedAssembly>();
+
/// <summary>
/// The assemblies in this list.
/// Needs locking for multi-threaded access!
@@ -101,6 +103,7 @@ internal XElement SaveAsXml()
void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
+ assemblyLookupCache.Clear();
// Whenever the assembly list is modified, mark it as dirty
// and enqueue a task that saves it once the UI has finished modifying the assembly list.
if (!dirty) {
@@ -111,6 +114,7 @@ void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArg
delegate {
dirty = false;
AssemblyListManager.SaveList(this);
+ assemblyLookupCache.Clear();
})
);
}
View
@@ -17,11 +17,11 @@
// DEALINGS IN THE SOFTWARE.
using System;
+using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Threading;
-
using Mono.Cecil;
namespace ICSharpCode.ILSpy
@@ -133,6 +133,8 @@ public void Dispose()
if (!disposed) {
disposed = true;
assemblyLoadDisableCount--;
+ // clear the lookup cache since we might have stored the lookups failed due to DisableAssemblyLoad()
+ MainWindow.Instance.CurrentAssemblyList.assemblyLookupCache.Clear();
@EdHarvey

EdHarvey Jun 23, 2011

Member

Wouldn't it be better to pass the AssemblyList in as a parameter in the DecrementAssemblyLoadDisableCount constructor rather than taking a dependency on MainWindow?

}
}
}
@@ -178,6 +180,11 @@ public IAssemblyResolver GetAssemblyResolver()
public LoadedAssembly LookupReferencedAssembly(string fullName)
{
+ return assemblyList.assemblyLookupCache.GetOrAdd(fullName, LookupReferencedAssemblyInternal);
+ }
+
+ LoadedAssembly LookupReferencedAssemblyInternal(string fullName)
+ {
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {
if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase))
return asm;

0 comments on commit a318ce6

Please sign in to comment.