Skip to content

Commit

Permalink
Cache the ThrowInstanceBodyRemoved helper (dotnet#1154)
Browse files Browse the repository at this point in the history
Improves wallclock time for compilation of a Hello World by ~3%. Looking up things by name is not exactly cheap and we do it a lot here.
  • Loading branch information
MichalStrehovsky authored May 23, 2021
1 parent 93e09a8 commit ce4290b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,22 @@ public TypeDesc ArrayOfTEnumeratorType
}
}

private MethodDesc _instanceMethodRemovedHelper;
public MethodDesc InstanceMethodRemovedHelper
{
get
{
if (_instanceMethodRemovedHelper == null)
{
// This helper is optional, but it's fine for this cache to be ineffective if that happens.
// Those scenarios are rare and typically deal with small compilations.
_instanceMethodRemovedHelper = TypeSystemContext.GetOptionalHelperEntryPoint("ThrowHelpers", "ThrowInstanceBodyRemoved");
}

return _instanceMethodRemovedHelper;
}
}

private NodeCache<MethodDesc, VirtualMethodUseNode> _virtMethods;

public DependencyNodeCore<NodeFactory> VirtualMethodUse(MethodDesc decl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public TentativeInstanceMethodNode(IMethodBodyNode methodNode)
protected override ISymbolNode GetTarget(NodeFactory factory)
{
// If the class library doesn't provide this helper, the optimization is disabled.
MethodDesc helper = factory.TypeSystemContext.GetOptionalHelperEntryPoint("ThrowHelpers", "ThrowInstanceBodyRemoved");
MethodDesc helper = factory.InstanceMethodRemovedHelper;
return helper == null ? RealBody: factory.MethodEntrypoint(helper);
}

Expand Down

0 comments on commit ce4290b

Please sign in to comment.