Skip to content

Commit a85fa88

Browse files
committed
perf: pass a binding argument's own object id to a callback
packageArgs probed ObjectTable's identity index for every object argument. A binding of the receiving runtime (a NativeScriptRuntimeBound whose tag matches) carries its object id, written before the tag and never reused, so it is passed as the hint instead; native resolves it like any other hint and falls back to the exact lookup when it no longer names a linked wrapper. The new benchmark row passes the callback object itself.
1 parent a5c973b commit a85fa88

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎test-app/app/src/main/assets/app/tests/benchmarks/jniBenchmarks.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ function buildBenchmarks() {
456456
},
457457
function () {
458458
return measureCallback("callback.oneObject(new, 16 classes)", callback, 6, 20000);
459+
},
460+
function () {
461+
return measureCallback("callback.oneObject(binding)", callback, 7, 20000);
459462
}
460463
];
461464
}

‎test-app/app/src/main/java/com/tns/tests/JniBench.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ public static long runCallbacks(Callback cb, int kind, int n) {
247247
case 6:
248248
for (int i = 0; i < n; i++) cb.oneObject(newOfClass(i));
249249
break;
250+
case 7:
251+
// The callback is itself a binding: the argument carries its object id.
252+
for (int i = 0; i < n; i++) cb.oneObject(cb);
253+
break;
250254
default:
251255
throw new IllegalArgumentException("kind " + kind);
252256
}

‎test-app/runtime/src/main/java/com/tns/Runtime.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,18 @@ private PackagedArgs packageArgs(Object... args) {
13641364
refs = new Object[len];
13651365
}
13661366
refs[i] = value;
1367-
int id = objectTable.findIdOptimistic(value);
1367+
int id = ObjectTable.NO_ID;
1368+
if (value instanceof NativeScriptRuntimeBound) {
1369+
// A binding of this runtime carries its id (written before the tag, never
1370+
// reused); native resolves it like an identity-index hint.
1371+
NativeScriptRuntimeBound bound = (NativeScriptRuntimeBound) value;
1372+
if (bound.getRuntimeTag__ns() == getRuntimeId() + 1) {
1373+
id = bound.getObjectId__ns();
1374+
}
1375+
}
1376+
if (id == ObjectTable.NO_ID) {
1377+
id = objectTable.findIdOptimistic(value);
1378+
}
13681379
long fresh = 0;
13691380
if (id == ObjectTable.NO_ID && objectTable.allowsConcurrentRegistration()) {
13701381
// Registered here rather than under the isolate lock, so threads calling

0 commit comments

Comments
 (0)