Browse Source

Type "where used" analyzer - reduce memory usage

Discard method bodies after use to reduce memory usage.
This lowers the overall memory required, and improves performance by
reducing the number of higher GC gen collections, promotions and heap
expansions
pull/550/head
Ed Harvey 10 years ago
parent
commit
70b19272a0
  1. 32
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeUsedByTreeNode.cs

32
ILSpy/TreeNodes/Analyzer/AnalyzedTypeUsedByTreeNode.cs

@ -126,18 +126,38 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -126,18 +126,38 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
private bool IsUsedInMethodDefinition(MethodDefinition method)
{
return IsUsedInMethodReference(method)
|| IsUsedInMethodBody(method.Body)
|| IsUsedInMethodBody(method)
|| IsUsedInCustomAttributes(method.CustomAttributes);
}
private bool IsUsedInMethodBody(MethodBody body)
private bool IsUsedInMethodBody(MethodDefinition method)
{
if (body == null)
if (method.Body == null)
return false;
return body.Instructions.Select(ins => ins.Operand as TypeReference).Any(IsUsedInTypeReference)
|| body.Instructions.Select(ins => ins.Operand as MethodReference).Any(IsUsedInMethodReference)
|| body.Instructions.Select(ins => ins.Operand as FieldReference).Any(IsUsedInFieldReference);
bool found = false;
foreach (var instruction in method.Body.Instructions) {
TypeReference tr = instruction.Operand as TypeReference;
if (IsUsedInTypeReference(tr)) {
found = true;
break;
}
FieldReference fr = instruction.Operand as FieldReference;
if (IsUsedInFieldReference(fr)) {
found = true;
break;
}
MethodReference mr = instruction.Operand as MethodReference;
if (IsUsedInMethodReference(mr)) {
found = true;
break;
}
}
method.Body = null; // discard body to reduce memory pressure & higher GC gen collections
return found;
}
private bool IsUsedInMethodParameters(IEnumerable<ParameterDefinition> parameters)

Loading…
Cancel
Save