Skip to content

Commit

Permalink
Instrument async method call batch preprocessing
Browse files Browse the repository at this point in the history
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<MethodCall>`, 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<MethodCall>` pre-processing.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D21435455

fbshipit-source-id: 4c5a9e2b73c1a2a49d7a8f224a0d30afe3a0c79c
  • Loading branch information
RSNara authored and facebook-github-bot committed May 14, 2020
1 parent 9f310a2 commit bf0e516
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ReactCommon/cxxreact/NativeToJsBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "NativeToJsBridge.h"

#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/NativeModulePerfLogger.h>
#include <folly/MoveWrapper.h>
#include <folly/json.h>
#include <glog/logging.h>
Expand Down Expand Up @@ -55,10 +56,14 @@ class JsToNativeBridge : public react::ExecutorDelegate {
m_batchHadNativeModuleOrTurboModuleCalls =
m_batchHadNativeModuleOrTurboModuleCalls || !calls.empty();

std::vector<MethodCall> 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);
}
Expand Down
3 changes: 3 additions & 0 deletions ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "jsireact/JSIExecutor.h"

#include <ReactCommon/NativeModulePerfLogger.h>
#include <cxxreact/JSBigString.h>
#include <cxxreact/ModuleRegistry.h>
#include <cxxreact/ReactMarker.h>
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit bf0e516

Please sign in to comment.