Skip to content

Commit 7e0ab89

Browse files
authored
Fix for perf degradation in method calls on polyglot arrays (#3781)
1 parent 4152962 commit 7e0ab89

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
- [Notify node status to the IDE][3729]
381381
- [Distinguish static and instance methods][3740]
382382
- [By-type pattern matching][3742]
383+
- [Fix performance of method calls on polyglot arrays][3781]
383384

384385
[3227]: https://github.com/enso-org/enso/pull/3227
385386
[3248]: https://github.com/enso-org/enso/pull/3248
@@ -431,6 +432,7 @@
431432
[3729]: https://github.com/enso-org/enso/pull/3729
432433
[3740]: https://github.com/enso-org/enso/pull/3740
433434
[3742]: https://github.com/enso-org/enso/pull/3742
435+
[3781]: https://github.com/enso-org/enso/pull/3781
434436

435437
# Enso 2.0.0-alpha.18 (2021-10-12)
436438

distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Standard.Base.Runtime.Ref
2121
Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1
2222
measure : Any -> Text -> Integer -> Integer -> Nothing
2323
measure = ~act -> label -> iter_size -> num_iters ->
24-
result = Ref.new 0
24+
result = Ref.new 0.0
2525
single_call = _ ->
2626
x1 = System.nano_time
2727
Runtime.no_inline act

engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Stateful doPolyglot(
172172
int thisArgumentPosition,
173173
@CachedLibrary(limit = "10") TypesLibrary methods,
174174
@CachedLibrary(limit = "10") InteropLibrary interop,
175-
@Bind("getPolyglotCallType(self, symbol.getName(), interop)")
175+
@Bind("getPolyglotCallType(self, symbol, interop)")
176176
HostMethodCallNode.PolyglotCallType polyglotCallType,
177177
@Cached ThunkExecutorNode argExecutor,
178178
@Cached HostMethodCallNode hostMethodCallNode,
@@ -194,7 +194,7 @@ Stateful doPolyglot(
194194
guards = {
195195
"!methods.hasType(self)",
196196
"!methods.hasSpecialDispatch(self)",
197-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TEXT"
197+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TEXT"
198198
})
199199
Stateful doConvertText(
200200
MaterializedFrame frame,
@@ -237,7 +237,7 @@ Stateful doConvertText(
237237
guards = {
238238
"!methods.hasType(self)",
239239
"!methods.hasSpecialDispatch(self)",
240-
"getPolyglotCallType(self, symbol.getName(), interop) == NOT_SUPPORTED"
240+
"getPolyglotCallType(self, symbol, interop) == NOT_SUPPORTED"
241241
})
242242
Stateful doFallback(
243243
MaterializedFrame frame,
@@ -252,7 +252,7 @@ Stateful doFallback(
252252
int thisArgumentPosition,
253253
@CachedLibrary(limit = "10") TypesLibrary methods,
254254
@CachedLibrary(limit = "10") InteropLibrary interop,
255-
@Bind("getPolyglotCallType(self, symbol.getName(), interop)")
255+
@Bind("getPolyglotCallType(self, symbol, interop)")
256256
HostMethodCallNode.PolyglotCallType polyglotCallType,
257257
@Cached MethodResolverNode methodResolverNode,
258258
@Cached IndirectInvokeFunctionNode invokeFunctionNode) {

engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Stateful doPolyglot(
177177
@CachedLibrary(limit = "10") TypesLibrary methods,
178178
@CachedLibrary(limit = "10") InteropLibrary interop,
179179
@Cached MethodResolverNode preResolveMethod,
180-
@Bind("getPolyglotCallType(self, symbol.getName(), interop, preResolveMethod)")
180+
@Bind("getPolyglotCallType(self, symbol, interop, preResolveMethod)")
181181
HostMethodCallNode.PolyglotCallType polyglotCallType,
182182
@Cached(value = "buildExecutors()") ThunkExecutorNode[] argExecutors,
183183
@Cached(value = "buildProfiles()", dimensions = 1) BranchProfile[] profiles,
@@ -214,7 +214,7 @@ Stateful doPolyglot(
214214
guards = {
215215
"!types.hasType(self)",
216216
"!types.hasSpecialDispatch(self)",
217-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TEXT"
217+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TEXT"
218218
})
219219
Stateful doConvertText(
220220
VirtualFrame frame,
@@ -242,7 +242,7 @@ Stateful doConvertText(
242242
guards = {
243243
"!types.hasType(self)",
244244
"!types.hasSpecialDispatch(self)",
245-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_ARRAY",
245+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_ARRAY",
246246
},
247247
rewriteOn = AbstractMethodError.class)
248248
Stateful doConvertArray(
@@ -272,7 +272,7 @@ Stateful doConvertArray(
272272
guards = {
273273
"!types.hasType(self)",
274274
"!types.hasSpecialDispatch(self)",
275-
"getPolyglotCallType(self, symbol.getName(), interop, methodResolverNode) == CONVERT_TO_ARRAY"
275+
"getPolyglotCallType(self, symbol, interop, methodResolverNode) == CONVERT_TO_ARRAY"
276276
},
277277
replaces = "doConvertArray")
278278
Stateful doConvertArrayWithCheck(
@@ -295,7 +295,7 @@ Stateful doConvertArrayWithCheck(
295295
guards = {
296296
"!types.hasType(self)",
297297
"!types.hasSpecialDispatch(self)",
298-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_DATE"
298+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_DATE"
299299
})
300300
Stateful doConvertDate(
301301
VirtualFrame frame,
@@ -323,7 +323,7 @@ Stateful doConvertDate(
323323
guards = {
324324
"!types.hasType(self)",
325325
"!types.hasSpecialDispatch(self)",
326-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_DATE_TIME"
326+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_DATE_TIME"
327327
})
328328
Stateful doConvertDateTime(
329329
VirtualFrame frame,
@@ -363,7 +363,7 @@ private ZonedDateTime dateTime(LocalDate date, LocalTime time, ZoneId zone) {
363363
guards = {
364364
"!types.hasType(self)",
365365
"!types.hasSpecialDispatch(self)",
366-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_ZONED_DATE_TIME"
366+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_ZONED_DATE_TIME"
367367
})
368368
Stateful doConvertZonedDateTime(
369369
VirtualFrame frame,
@@ -393,7 +393,7 @@ Stateful doConvertZonedDateTime(
393393
guards = {
394394
"!types.hasType(self)",
395395
"!types.hasSpecialDispatch(self)",
396-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TIME_ZONE"
396+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TIME_ZONE"
397397
})
398398
Stateful doConvertZone(
399399
VirtualFrame frame,
@@ -421,7 +421,7 @@ Stateful doConvertZone(
421421
guards = {
422422
"!types.hasType(self)",
423423
"!types.hasSpecialDispatch(self)",
424-
"getPolyglotCallType(self, symbol.getName(), interop) == CONVERT_TO_TIME_OF_DAY"
424+
"getPolyglotCallType(self, symbol, interop) == CONVERT_TO_TIME_OF_DAY"
425425
})
426426
Stateful doConvertTimeOfDay(
427427
VirtualFrame frame,
@@ -449,7 +449,7 @@ Stateful doConvertTimeOfDay(
449449
guards = {
450450
"!methods.hasType(self)",
451451
"!methods.hasSpecialDispatch(self)",
452-
"getPolyglotCallType(self, symbol.getName(), interop) == NOT_SUPPORTED"
452+
"getPolyglotCallType(self, symbol, interop) == NOT_SUPPORTED"
453453
})
454454
Stateful doFallback(
455455
VirtualFrame frame,

engine/runtime/src/main/java/org/enso/interpreter/node/callable/resolver/HostMethodCallNode.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ public boolean isInteropLibrary() {
9898
* used.
9999
*
100100
* @param self the method call target
101-
* @param methodName the method name
101+
* @param symbol symbol representing method to be resolved
102102
* @param library an instance of interop library to use for interacting with the target
103103
* @return a {@link PolyglotCallType} to use for this target and method
104104
*/
105105
public static PolyglotCallType getPolyglotCallType(
106-
Object self, String methodName, InteropLibrary library) {
107-
return getPolyglotCallType(self, methodName, library, null);
106+
Object self, UnresolvedSymbol symbol, InteropLibrary library) {
107+
return getPolyglotCallType(self, symbol, library, null);
108108
}
109109

110110
/**
111111
* Returns a token instructing the caller about what mode of calling the given method should be
112112
* used.
113113
*
114114
* @param self the method call target
115-
* @param methodName the method name
115+
* @param symbol symbol representing method to be resolved
116116
* @param library an instance of interop library to use for interacting with the target
117117
* @param methodResolverNode {@code null} or real instances of the node to resolve methods
118118
* @return a {@link PolyglotCallType} to use for this target and method
119119
*/
120120
public static PolyglotCallType getPolyglotCallType(
121121
Object self,
122-
String methodName,
122+
UnresolvedSymbol symbol,
123123
InteropLibrary library,
124124
MethodResolverNode methodResolverNode) {
125125
if (library.isDate(self)) {
@@ -142,7 +142,6 @@ public static PolyglotCallType getPolyglotCallType(
142142
if (methodResolverNode != null) {
143143
var ctx = Context.get(library);
144144
var arrayType = ctx.getBuiltins().array();
145-
var symbol = UnresolvedSymbol.build(methodName, ctx.getBuiltins().getScope());
146145
var fn = methodResolverNode.execute(arrayType, symbol);
147146
if (fn != null) {
148147
return PolyglotCallType.CONVERT_TO_ARRAY;
@@ -152,6 +151,7 @@ public static PolyglotCallType getPolyglotCallType(
152151
}
153152
}
154153

154+
String methodName = symbol.getName();
155155
if (library.isMemberInvocable(self, methodName)) {
156156
return PolyglotCallType.CALL_METHOD;
157157
} else if (library.isMemberReadable(self, methodName)) {

0 commit comments

Comments
 (0)