From 80a65be7230659ff3efdd1ca6c2f8b6d59dc0c15 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 3 May 2023 17:40:48 +0200 Subject: [PATCH] Cache resolution of symbol for Any Otherwise things can go horribly slow. Closes #6523. --- .../interpreter/node/callable/InvokeMethodNode.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java index 670882debfa36..d44dc027f7e0d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java @@ -112,7 +112,8 @@ Object doFunctionalDispatch( Object self, Object[] arguments, @CachedLibrary(limit = "10") TypesLibrary typesLibrary, - @Cached MethodResolverNode methodResolverNode) { + @Cached MethodResolverNode methodResolverNode, + @Cached("anyFunction(symbol)") Function anyFun) { Type selfTpe = typesLibrary.getType(self); Function function = methodResolverNode.expectNonNull(self, selfTpe, symbol); @@ -122,7 +123,6 @@ Object doFunctionalDispatch( // and the method is invoked statically, i.e. type of self is the eigentype, // then we want to disambiguate method resolution by always resolved to the one in Any. if (where instanceof MethodRootNode node && typeCanOverride(node, EnsoContext.get(this))) { - Function anyFun = symbol.getScope().lookupMethodDefinition(EnsoContext.get(this).getBuiltins().any(), symbol.getName()); if (anyFun != null) { function = anyFun; } @@ -130,6 +130,11 @@ Object doFunctionalDispatch( return invokeFunctionNode.execute(function, frame, state, arguments); } + Function anyFunction(UnresolvedSymbol symbol) { + Type any = EnsoContext.get(this).getBuiltins().any(); + return symbol.getScope().lookupMethodDefinition(any, symbol.getName()); + } + private boolean typeCanOverride(MethodRootNode node, EnsoContext ctx) { Type methodOwnerType = node.getType(); Builtins builtins = ctx.getBuiltins(); @@ -137,7 +142,6 @@ private boolean typeCanOverride(MethodRootNode node, EnsoContext ctx) { Type warning = builtins.warning(); Type panic = builtins.panic(); return methodOwnerType.isEigenType() - && builtins.nothing() != methodOwnerType && any.getEigentype() != methodOwnerType && panic.getEigentype() != methodOwnerType