Skip to content

Commit d870463

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[benchmarks/ffi] Add FfiCall benchmark with Handles
On x64 desktop in JIT the trampolines with Handles are a bit slower than trampolines passing integers or Pointers. FfiCall.Uint64x01(RunTime): 200.8482627033541 us. FfiCall.PointerUint8x01(RunTime): 261.3910088865656 us. FfiCall.Handlex01(RunTime): 355.4978670458585 us. FfiCall.Handlex02(RunTime): 384.86376755820663 us. FfiCall.Handlex04(RunTime): 492.896007885658 us. FfiCall.Handlex10(RunTime): 846.1214043993232 us. FfiCall.Handlex20(RunTime): 1193.412291169451 us. Issue: #36858 Issue: #41319 New issue for optimizing multiple handles: #42341 Also cleans up dart2/native which was erroneously left over from the benchmark duplication for NNBD. Change-Id: I81223fefc47129d00984492efb9502d5449f0d4a Cq-Include-Trybots: luci.dart.try:benchmark-linux-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145593 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Jonas Termansen <[email protected]>
1 parent 28606d0 commit d870463

File tree

8 files changed

+514
-202
lines changed

8 files changed

+514
-202
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ deps = {
505505
"packages": [
506506
{
507507
"package": "dart/benchmarks/fficall",
508-
"version": "_AKfaNTE0blKZwinuNMETidy44AK5b-u_rXmdBpat9UC",
508+
"version": "ebF5aRXKDananlaN4Y8b0bbCNHT1MnkGbWqfpCpiND4C",
509509
},
510510
],
511511
"dep_type": "cipd",

benchmarks/FfiCall/dart/FfiCall.dart

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,67 @@ typedef Function20PointerUint8 = Pointer<Uint8> Function(
297297
Function20PointerUint8 function20PointerUint8 = ffiTestFunctions.lookupFunction<
298298
Function20PointerUint8, Function20PointerUint8>("Function20PointerUint8");
299299

300+
final function1handle = ffiTestFunctions.lookupFunction<Handle Function(Handle),
301+
Object Function(Object)>("Function1Handle");
302+
303+
final function2handle = ffiTestFunctions.lookupFunction<
304+
Handle Function(Handle, Handle),
305+
Object Function(Object, Object)>("Function2Handle");
306+
307+
final function4handle = ffiTestFunctions.lookupFunction<
308+
Handle Function(Handle, Handle, Handle, Handle),
309+
Object Function(Object, Object, Object, Object)>("Function4Handle");
310+
311+
final function10handle = ffiTestFunctions.lookupFunction<
312+
Handle Function(Handle, Handle, Handle, Handle, Handle, Handle, Handle,
313+
Handle, Handle, Handle),
314+
Object Function(Object, Object, Object, Object, Object, Object, Object,
315+
Object, Object, Object)>("Function10Handle");
316+
317+
final function20handle = ffiTestFunctions.lookupFunction<
318+
Handle Function(
319+
Handle,
320+
Handle,
321+
Handle,
322+
Handle,
323+
Handle,
324+
Handle,
325+
Handle,
326+
Handle,
327+
Handle,
328+
Handle,
329+
Handle,
330+
Handle,
331+
Handle,
332+
Handle,
333+
Handle,
334+
Handle,
335+
Handle,
336+
Handle,
337+
Handle,
338+
Handle),
339+
Object Function(
340+
Object,
341+
Object,
342+
Object,
343+
Object,
344+
Object,
345+
Object,
346+
Object,
347+
Object,
348+
Object,
349+
Object,
350+
Object,
351+
Object,
352+
Object,
353+
Object,
354+
Object,
355+
Object,
356+
Object,
357+
Object,
358+
Object,
359+
Object)>("Function20Handle");
360+
300361
//
301362
// Trampoline call.
302363
//
@@ -597,6 +658,69 @@ Pointer<Uint8> doCall20PointerUint8(
597658
return x;
598659
}
599660

661+
Object doCall1Handle(int length, Object p1) {
662+
Object x = p1;
663+
for (int i = 0; i < length; i++) {
664+
x = function1handle(x);
665+
}
666+
return x;
667+
}
668+
669+
Object doCall2Handle(int length, Object p1, Object p2) {
670+
Object x = p1;
671+
for (int i = 0; i < length; i++) {
672+
x = function2handle(x, p2);
673+
}
674+
return x;
675+
}
676+
677+
Object doCall4Handle(int length, Object p1, Object p2, Object p3, Object p4) {
678+
Object x = p1;
679+
for (int i = 0; i < length; i++) {
680+
x = function4handle(x, p2, p3, p4);
681+
}
682+
return x;
683+
}
684+
685+
Object doCall10Handle(int length, Object p1, Object p2, Object p3, Object p4,
686+
Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) {
687+
Object x = p1;
688+
for (int i = 0; i < length; i++) {
689+
x = function10handle(x, p2, p3, p4, p5, p6, p7, p8, p9, p10);
690+
}
691+
return x;
692+
}
693+
694+
Object doCall20Handle(
695+
int length,
696+
Object p1,
697+
Object p2,
698+
Object p3,
699+
Object p4,
700+
Object p5,
701+
Object p6,
702+
Object p7,
703+
Object p8,
704+
Object p9,
705+
Object p10,
706+
Object p11,
707+
Object p12,
708+
Object p13,
709+
Object p14,
710+
Object p15,
711+
Object p16,
712+
Object p17,
713+
Object p18,
714+
Object p19,
715+
Object p20) {
716+
Object x = p1;
717+
for (int i = 0; i < length; i++) {
718+
x = function20handle(x, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13,
719+
p14, p15, p16, p17, p18, p19, p20);
720+
}
721+
return x;
722+
}
723+
600724
//
601725
// Benchmark fixtures.
602726
//
@@ -1106,6 +1230,109 @@ class PointerUint8x20 extends BenchmarkBase {
11061230
}
11071231
}
11081232

1233+
class MyClass {
1234+
int a;
1235+
MyClass(this.a);
1236+
}
1237+
1238+
class Handlex01 extends BenchmarkBase {
1239+
Handlex01() : super("FfiCall.Handlex01");
1240+
1241+
void run() {
1242+
final p1 = MyClass(123);
1243+
final x = doCall1Handle(N, p1);
1244+
1245+
if (!identical(p1, x)) {
1246+
throw Exception("$name: Unexpected result: $x");
1247+
}
1248+
}
1249+
}
1250+
1251+
class Handlex02 extends BenchmarkBase {
1252+
Handlex02() : super("FfiCall.Handlex02");
1253+
1254+
void run() {
1255+
final p1 = MyClass(123);
1256+
final p2 = MyClass(2);
1257+
final x = doCall2Handle(N, p1, p2);
1258+
1259+
if (!identical(p1, x)) {
1260+
throw Exception("$name: Unexpected result: $x");
1261+
}
1262+
}
1263+
}
1264+
1265+
class Handlex04 extends BenchmarkBase {
1266+
Handlex04() : super("FfiCall.Handlex04");
1267+
1268+
void run() {
1269+
final p1 = MyClass(123);
1270+
final p2 = MyClass(2);
1271+
final p3 = MyClass(3);
1272+
final p4 = MyClass(4);
1273+
final x = doCall4Handle(N, p1, p2, p3, p4);
1274+
1275+
if (!identical(p1, x)) {
1276+
throw Exception("$name: Unexpected result: $x");
1277+
}
1278+
}
1279+
}
1280+
1281+
class Handlex10 extends BenchmarkBase {
1282+
Handlex10() : super("FfiCall.Handlex10");
1283+
1284+
void run() {
1285+
final p1 = MyClass(123);
1286+
final p2 = MyClass(2);
1287+
final p3 = MyClass(3);
1288+
final p4 = MyClass(4);
1289+
final p5 = MyClass(5);
1290+
final p6 = MyClass(6);
1291+
final p7 = MyClass(7);
1292+
final p8 = MyClass(8);
1293+
final p9 = MyClass(9);
1294+
final p10 = MyClass(10);
1295+
final x = doCall10Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
1296+
1297+
if (!identical(p1, x)) {
1298+
throw Exception("$name: Unexpected result: $x");
1299+
}
1300+
}
1301+
}
1302+
1303+
class Handlex20 extends BenchmarkBase {
1304+
Handlex20() : super("FfiCall.Handlex20");
1305+
1306+
void run() {
1307+
final p1 = MyClass(123);
1308+
final p2 = MyClass(2);
1309+
final p3 = MyClass(3);
1310+
final p4 = MyClass(4);
1311+
final p5 = MyClass(5);
1312+
final p6 = MyClass(6);
1313+
final p7 = MyClass(7);
1314+
final p8 = MyClass(8);
1315+
final p9 = MyClass(9);
1316+
final p10 = MyClass(10);
1317+
final p11 = MyClass(11);
1318+
final p12 = MyClass(12);
1319+
final p13 = MyClass(13);
1320+
final p14 = MyClass(14);
1321+
final p15 = MyClass(15);
1322+
final p16 = MyClass(16);
1323+
final p17 = MyClass(17);
1324+
final p18 = MyClass(18);
1325+
final p19 = MyClass(19);
1326+
final p20 = MyClass(20);
1327+
final x = doCall20Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
1328+
p12, p13, p14, p15, p16, p17, p18, p19, p20);
1329+
1330+
if (!identical(p1, x)) {
1331+
throw Exception("$name: Unexpected result: $x");
1332+
}
1333+
}
1334+
}
1335+
11091336
//
11101337
// Main driver.
11111338
//
@@ -1144,6 +1371,11 @@ main() {
11441371
() => PointerUint8x04(),
11451372
() => PointerUint8x10(),
11461373
() => PointerUint8x20(),
1374+
() => Handlex01(),
1375+
() => Handlex02(),
1376+
() => Handlex04(),
1377+
() => Handlex10(),
1378+
() => Handlex20(),
11471379
];
11481380
benchmarks.forEach((benchmark) => benchmark().report());
11491381
}

0 commit comments

Comments
 (0)