Move preallocation calls to background under MC

Summary:
Preallocation can take 10-20% of time when creating new nodes. (according to systrace measurements). At the moment, we are executing all preallocation calls in JS thread, potentially slowing down the progress there. Moving them to bg thread is a simple micro-optimization that ensures we return the node to JS as soon as possible.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D32677843

fbshipit-source-id: 3df47ae9aa365a8db720d71e2423c87659e9128c
This commit is contained in:
Andrei Shikov 2021-11-30 09:14:52 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 041398a775
Коммит 290dae9df5
2 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -596,6 +596,9 @@ void Binding::installFabricUIManager(
enableEarlyEventEmitterUpdate_ = reactNativeConfig_->getBool(
"react_fabric:enable_early_event_emitter_update");
dispatchPreallocationInBackground_ = reactNativeConfig_->getBool(
"react_native_new_architecture:dispatch_preallocation_in_bg");
auto toolbox = SchedulerToolbox{};
toolbox.contextContainer = contextContainer;
toolbox.componentRegistryFactory = componentsRegistry->buildRegistryFunction;
@ -1246,7 +1249,14 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation(
return;
}
preallocateShadowView(surfaceId, shadowView);
if (dispatchPreallocationInBackground_) {
auto backgroundExecutor = backgroundExecutor_->get();
backgroundExecutor([this, surfaceId, shadowView = std::move(shadowView)] {
preallocateShadowView(surfaceId, shadowView);
});
} else {
preallocateShadowView(surfaceId, shadowView);
}
}
void Binding::schedulerDidCloneShadowNode(
@ -1274,7 +1284,14 @@ void Binding::schedulerDidCloneShadowNode(
if (!oldShadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView) &&
newShadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView)) {
auto shadowView = ShadowView(newShadowNode);
preallocateShadowView(surfaceId, shadowView);
if (dispatchPreallocationInBackground_) {
auto backgroundExecutor = backgroundExecutor_->get();
backgroundExecutor([this, surfaceId, shadowView = std::move(shadowView)] {
preallocateShadowView(surfaceId, shadowView);
});
} else {
preallocateShadowView(surfaceId, shadowView);
}
}
}

Просмотреть файл

@ -201,6 +201,7 @@ class Binding : public jni::HybridClass<Binding>,
bool enableEarlyEventEmitterUpdate_{false};
bool disableRevisionCheckForPreallocation_{false};
bool enableEventEmitterRawPointer_{false};
bool dispatchPreallocationInBackground_{false};
};
} // namespace react