Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for perf degradation in method calls on polyglot arrays #3781

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ 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);
}

/**
* Returns a token instructing the caller about what mode of calling the given method should be
* 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)) {
Expand All @@ -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;
Expand All @@ -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)) {
Expand Down