From bf0e516086fdc91c9d761f17640bf855d1e42a83 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 13 May 2020 20:24:37 -0700 Subject: [PATCH] Instrument async method call batch preprocessing Summary: NativeModule async method calls are queued up on the JS side, and flushed to C++ on every Native -> JS call. Before we execute the batch of async NativeModule method calls, we convert it (a JS object) from a `jsi::Value` to a `folly::dynamic` object in `JSIExecutor::callNativeModules`. Then, in `JsToNativeBridge::callNativeModules`, we convert this `folly::dynamic` object into an `std::vector`, before finally looping over these `MethodCall`s and invoking each NativeModule async method call. The markers I'm adding in this diff measure this `jsi::Value -> folly::dynamic -> std::vector` pre-processing. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D21435455 fbshipit-source-id: 4c5a9e2b73c1a2a49d7a8f224a0d30afe3a0c79c --- ReactCommon/cxxreact/NativeToJsBridge.cpp | 7 ++++++- ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 64b0673423b..be11a075f97 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -8,6 +8,7 @@ #include "NativeToJsBridge.h" #include +#include #include #include #include @@ -55,10 +56,14 @@ class JsToNativeBridge : public react::ExecutorDelegate { m_batchHadNativeModuleOrTurboModuleCalls = m_batchHadNativeModuleOrTurboModuleCalls || !calls.empty(); + std::vector methodCalls = parseMethodCalls(std::move(calls)); + NativeModulePerfLogger::getInstance().asyncMethodCallBatchPreprocessEnd( + (int)methodCalls.size()); + // An exception anywhere in here stops processing of the batch. This // was the behavior of the Android bridge, and since exception handling // terminates the whole bridge, there's not much point in continuing. - for (auto &call : parseMethodCalls(std::move(calls))) { + for (auto &call : methodCalls) { m_registry->callNativeMethod( call.moduleId, call.methodId, std::move(call.arguments), call.callId); } diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index fd77eba63e6..6490e4d94c5 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -7,6 +7,7 @@ #include "jsireact/JSIExecutor.h" +#include #include #include #include @@ -383,6 +384,8 @@ void JSIExecutor::callNativeModules(const Value &queue, bool isEndOfBatch) { .getPropertyAsFunction(*runtime_, "stringify").call(*runtime_, queue) .getString(*runtime_).utf8(*runtime_); #endif + NativeModulePerfLogger::getInstance().asyncMethodCallBatchPreprocessStart(); + delegate_->callNativeModules( *this, dynamicFromValue(*runtime_, queue), isEndOfBatch); }