diff --git a/CHANGELOG.md b/CHANGELOG.md index 1372ecb5c67e..d71b0a6dbed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -380,6 +380,7 @@ - [Notify node status to the IDE][3729] - [Distinguish static and instance methods][3740] - [By-type pattern matching][3742] +- [Fix performance of method calls on polyglot arrays][3781] [3227]: https://github.com/enso-org/enso/pull/3227 [3248]: https://github.com/enso-org/enso/pull/3248 @@ -431,6 +432,7 @@ [3729]: https://github.com/enso-org/enso/pull/3729 [3740]: https://github.com/enso-org/enso/pull/3740 [3742]: https://github.com/enso-org/enso/pull/3742 +[3781]: https://github.com/enso-org/enso/pull/3781 # Enso 2.0.0-alpha.18 (2021-10-12) diff --git a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso index 42593908a298..9b6bfe9cd405 100644 --- a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso +++ b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso @@ -21,7 +21,7 @@ import Standard.Base.Runtime.Ref Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1 measure : Any -> Text -> Integer -> Integer -> Nothing measure = ~act -> label -> iter_size -> num_iters -> - result = Ref.new 0 + result = Ref.new 0.0 single_call = _ -> x1 = System.nano_time Runtime.no_inline act diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java index 7bdb2d3f257c..03eef4c2146e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java @@ -172,7 +172,7 @@ Stateful doPolyglot( int thisArgumentPosition, @CachedLibrary(limit = "10") TypesLibrary methods, @CachedLibrary(limit = "10") InteropLibrary interop, - @Bind("getPolyglotCallType(self, symbol.getName(), interop)") + @Bind("getPolyglotCallType(self, symbol, interop)") HostMethodCallNode.PolyglotCallType polyglotCallType, @Cached ThunkExecutorNode argExecutor, @Cached HostMethodCallNode hostMethodCallNode, @@ -194,7 +194,7 @@ Stateful doPolyglot( guards = { "!methods.hasType(self)", "!methods.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TEXT" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TEXT" }) Stateful doConvertText( MaterializedFrame frame, @@ -237,7 +237,7 @@ Stateful doConvertText( guards = { "!methods.hasType(self)", "!methods.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == NOT_SUPPORTED" + "getPolyglotCallType(self, symbol, interop) == NOT_SUPPORTED" }) Stateful doFallback( MaterializedFrame frame, @@ -252,7 +252,7 @@ Stateful doFallback( int thisArgumentPosition, @CachedLibrary(limit = "10") TypesLibrary methods, @CachedLibrary(limit = "10") InteropLibrary interop, - @Bind("getPolyglotCallType(self, symbol.getName(), interop)") + @Bind("getPolyglotCallType(self, symbol, interop)") HostMethodCallNode.PolyglotCallType polyglotCallType, @Cached MethodResolverNode methodResolverNode, @Cached IndirectInvokeFunctionNode invokeFunctionNode) { 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 6aac516d90ec..4907ec7b983a 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 @@ -177,7 +177,7 @@ Stateful doPolyglot( @CachedLibrary(limit = "10") TypesLibrary methods, @CachedLibrary(limit = "10") InteropLibrary interop, @Cached MethodResolverNode preResolveMethod, - @Bind("getPolyglotCallType(self, symbol.getName(), interop, preResolveMethod)") + @Bind("getPolyglotCallType(self, symbol, interop, preResolveMethod)") HostMethodCallNode.PolyglotCallType polyglotCallType, @Cached(value = "buildExecutors()") ThunkExecutorNode[] argExecutors, @Cached(value = "buildProfiles()", dimensions = 1) BranchProfile[] profiles, @@ -214,7 +214,7 @@ Stateful doPolyglot( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TEXT" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TEXT" }) Stateful doConvertText( VirtualFrame frame, @@ -242,7 +242,7 @@ Stateful doConvertText( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_ARRAY", + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_ARRAY", }, rewriteOn = AbstractMethodError.class) Stateful doConvertArray( @@ -272,7 +272,7 @@ Stateful doConvertArray( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop, methodResolverNode) == CONVERT_TO_ARRAY" + "getPolyglotCallType(self, symbol, interop, methodResolverNode) == CONVERT_TO_ARRAY" }, replaces = "doConvertArray") Stateful doConvertArrayWithCheck( @@ -295,7 +295,7 @@ Stateful doConvertArrayWithCheck( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_DATE" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_DATE" }) Stateful doConvertDate( VirtualFrame frame, @@ -323,7 +323,7 @@ Stateful doConvertDate( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_DATE_TIME" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_DATE_TIME" }) Stateful doConvertDateTime( VirtualFrame frame, @@ -363,7 +363,7 @@ private ZonedDateTime dateTime(LocalDate date, LocalTime time, ZoneId zone) { guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_ZONED_DATE_TIME" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_ZONED_DATE_TIME" }) Stateful doConvertZonedDateTime( VirtualFrame frame, @@ -393,7 +393,7 @@ Stateful doConvertZonedDateTime( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TIME_ZONE" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TIME_ZONE" }) Stateful doConvertZone( VirtualFrame frame, @@ -421,7 +421,7 @@ Stateful doConvertZone( guards = { "!types.hasType(self)", "!types.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TIME_OF_DAY" + "getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TIME_OF_DAY" }) Stateful doConvertTimeOfDay( VirtualFrame frame, @@ -449,7 +449,7 @@ Stateful doConvertTimeOfDay( guards = { "!methods.hasType(self)", "!methods.hasSpecialDispatch(self)", - "getPolyglotCallType(self, symbol.getName(), interop) == NOT_SUPPORTED" + "getPolyglotCallType(self, symbol, interop) == NOT_SUPPORTED" }) Stateful doFallback( VirtualFrame frame, diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java index ce52d9bdb33d..9b416894a1bb 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java @@ -98,13 +98,13 @@ public boolean isInteropLibrary() { * used. * * @param self the method call target - * @param methodName the method name + * @param symbol symbol representing method to be resolved * @param library an instance of interop library to use for interacting with the target * @return a {@link PolyglotCallType} to use for this target and method */ public static PolyglotCallType getPolyglotCallType( - Object self, String methodName, InteropLibrary library) { - return getPolyglotCallType(self, methodName, library, null); + Object self, UnresolvedSymbol symbol, InteropLibrary library) { + return getPolyglotCallType(self, symbol, library, null); } /** @@ -112,14 +112,14 @@ public static PolyglotCallType getPolyglotCallType( * used. * * @param self the method call target - * @param methodName the method name + * @param symbol symbol representing method to be resolved * @param library an instance of interop library to use for interacting with the target * @param methodResolverNode {@code null} or real instances of the node to resolve methods * @return a {@link PolyglotCallType} to use for this target and method */ public static PolyglotCallType getPolyglotCallType( Object self, - String methodName, + UnresolvedSymbol symbol, InteropLibrary library, MethodResolverNode methodResolverNode) { if (library.isDate(self)) { @@ -142,7 +142,6 @@ public static PolyglotCallType getPolyglotCallType( if (methodResolverNode != null) { var ctx = Context.get(library); var arrayType = ctx.getBuiltins().array(); - var symbol = UnresolvedSymbol.build(methodName, ctx.getBuiltins().getScope()); var fn = methodResolverNode.execute(arrayType, symbol); if (fn != null) { return PolyglotCallType.CONVERT_TO_ARRAY; @@ -152,6 +151,7 @@ public static PolyglotCallType getPolyglotCallType( } } + String methodName = symbol.getName(); if (library.isMemberInvocable(self, methodName)) { return PolyglotCallType.CALL_METHOD; } else if (library.isMemberReadable(self, methodName)) {