Skip to content

Commit bec6706

Browse files
committed
perf(ffi): cache resolved instance-method host functions
Avoid reallocating the dispatch host function on every method access.
1 parent 381301a commit bec6706

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

NativeScript/ffi/shared/bridge/HostObjects.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ throw JSError(runtime,
12191219
std::weak_ptr<NativeApiObjectHostObject> weakSelf =
12201220
shared_from_this();
12211221
std::string memberName = property;
1222-
return Function::createFromHostFunction(
1222+
Value methodFunction = Function::createFromHostFunction(
12231223
runtime, PropNameID::forAscii(runtime, property.c_str()), 0,
12241224
[bridge, object, weakSelf, memberName](
12251225
Runtime& runtime, const Value&, const Value* args,
@@ -1261,6 +1261,10 @@ throw JSError(
12611261
selected->selectorName, selected, args,
12621262
count);
12631263
});
1264+
// Cache the resolved host function so repeated method access does not
1265+
// reallocate it on every call (hot path).
1266+
bridge_->setObjectExpando(runtime, object_, property, methodFunction);
1267+
return methodFunction;
12641268
}
12651269
}
12661270
}

0 commit comments

Comments
 (0)