Commit 840f04a
committed
JniMemberInfoLookup timing
Commit d1a9951 showed that *for just field lookup*, the idea of a
`ref struct JniMemberInfoLookup` *might* be a good idea.
Now that we've expanded `JniMemberInfoLookup` plumbing to include
*method* lookup, we can throw it into `TimingTests.cs` and see how it
compares!
The answer is that `ref struct`s and `Span<T>` are *not* magical
performance sauce with magical JIT support, and this is with CoreCLR!
Method Lookup + Invoke Timing:
Traditional: 00:00:00.0175778
No caching: 00:00:00.0202369
Dict w/ lock: 00:00:00.0181357
ConcurrentDict: 00:00:00.0220411
JniPeerMembers: 00:00:00.0209174
JPM+Lookup: 00:00:00.0186421
(I)I virtual+traditional: 00:00:00.0000600
(I)I virtual+JniPeerMembers: 00:00:00.0000588
(I)I virtual+JPM+Lookup: 00:00:00.0007137
The new timings are `JPM+Lookup` and `virtual+JPM+Lookup`.
// JniPeerMembers
return _members.InstanceMethods.InvokeVirtualObjectMethod("toString.()Ljava/lang/String;", this, null);
// JPM+Lookup
var member = new JniMemberInfoLookup("toString.()Ljava/lang/String;", "toString"u8, "()Ljava/lang/String;"u8);
ReadOnlySpan<JniArgumentValue> args = null;
return _members.InstanceMethods.InvokeVirtualObjectMethod (member, this, args);
We see that JPM+Lookup is 11% *faster* when no arguments are involved.
Nice!
Throw an argument into the mix:
// (I)I virtual+JniPeerMembers
var args = stackalloc JniArgumentValue [1];
args [0] = new JniArgumentValue (value);
return _members.InstanceMethods.InvokeVirtualInt32Method ("VirtualIntMethod1Args.(I)I", this, args);
// (I)I virtual+JPM+Lookup
var member = new JniMemberInfoLookup (
"VirtualIntMethod1Args.(I)I",
"VirtualIntMethod1Args"u8,
"(I)I"u8
);
var args = stackalloc JniArgumentValue [1];
args [0] = new JniArgumentValue (value);
return _members.InstanceMethods.InvokeVirtualInt32Method (member, this, new ReadOnlySpan<JniArgumentValue> (args, 1));
and we're now a *whole order of magnitude worse*, taking 12.1x longer.
Which quickly makes this idea as-is unworkable.
Maybe it's the ReadOnlySpan<T> usage, and if I went back to straight
`JniArgumentValue*` values it would be better?1 parent bd7dddd commit 840f04a
File tree
3 files changed
+39
-1
lines changed- tests/Java.Interop-PerformanceTests
- Java.Interop
3 files changed
+39
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
131 | 144 | | |
132 | 145 | | |
133 | 146 | | |
| |||
277 | 290 | | |
278 | 291 | | |
279 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
280 | 304 | | |
281 | 305 | | |
282 | 306 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
360 | 366 | | |
361 | 367 | | |
362 | 368 | | |
| |||
370 | 376 | | |
371 | 377 | | |
372 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
373 | 385 | | |
374 | 386 | | |
375 | 387 | | |
376 | 388 | | |
377 | 389 | | |
378 | 390 | | |
379 | 391 | | |
| 392 | + | |
380 | 393 | | |
381 | 394 | | |
382 | 395 | | |
| 396 | + | |
383 | 397 | | |
384 | 398 | | |
385 | 399 | | |
| |||
0 commit comments