Skip to content

Commit

Permalink
Ship and delete mapBufferSerialization for Text measurement
Browse files Browse the repository at this point in the history
Summary:
In this diff I'm shipping and deleting mapBufferSerialization for Text measurement

changelog: [internal] internal

Reviewed By: NickGerleman

Differential Revision: D40348982

fbshipit-source-id: 7336cbe055a55d7d8d4f0a723049842bae1defb5
  • Loading branch information
mdvacca authored and facebook-github-bot committed Oct 18, 2022
1 parent e87cdc7 commit 22b6e1c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.common.mapbuffer.MapBuffer;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.IViewManagerWithChildren;
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
Expand Down Expand Up @@ -132,13 +131,10 @@ public boolean needsCustomLayoutForChildren() {
@Override
public Object updateState(
ReactTextView view, ReactStylesDiffMap props, StateWrapper stateWrapper) {
if (ReactFeatureFlags.mapBufferSerializationEnabled) {
MapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
if (stateMapBuffer != null) {
return getReactTextUpdate(view, props, stateMapBuffer);
}
MapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
if (stateMapBuffer != null) {
return getReactTextUpdate(view, props, stateMapBuffer);
}

ReadableNativeMap state = stateWrapper.getStateData();
if (state == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.mapbuffer.MapBuffer;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.FabricViewStateManager;
Expand Down Expand Up @@ -1295,11 +1294,9 @@ public Object updateState(

stateManager.setStateWrapper(stateWrapper);

if (ReactFeatureFlags.mapBufferSerializationEnabled) {
MapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
if (stateMapBuffer != null) {
return getReactTextUpdate(view, props, stateMapBuffer);
}
MapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
if (stateMapBuffer != null) {
return getReactTextUpdate(view, props, stateMapBuffer);
}

ReadableNativeMap state = stateWrapper.getStateData();
Expand Down
4 changes: 0 additions & 4 deletions ReactAndroid/src/main/jni/react/fabric/Binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,6 @@ void Binding::installFabricUIManager(
// Keep reference to config object and cache some feature flags here
reactNativeConfig_ = config;

contextContainer->insert(
"MapBufferSerializationEnabled",
getFeatureFlagValue("mapBufferSerializationEnabled"));

contextContainer->insert(
"CalculateTransformedFramesEnabled",
getFeatureFlagValue("calculateTransformedFramesEnabled"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ Size measureAndroidComponentMapBuffer(
TextLayoutManager::TextLayoutManager(
const ContextContainer::Shared &contextContainer)
: contextContainer_(contextContainer),
mapBufferSerializationEnabled_(
contextContainer->at<bool>("MapBufferSerializationEnabled")),
measureCache_(
contextContainer->at<bool>("EnableLargeTextMeasureCache")
? 1024
Expand All @@ -171,11 +169,8 @@ TextMeasurement TextLayoutManager::measure(
telemetry->willMeasureText();
}

auto measurement = mapBufferSerializationEnabled_
? doMeasureMapBuffer(
attributedString, paragraphAttributes, layoutConstraints)
: doMeasure(
attributedString, paragraphAttributes, layoutConstraints);
auto measurement = doMeasureMapBuffer(
attributedString, paragraphAttributes, layoutConstraints);

if (telemetry != nullptr) {
telemetry->didMeasureText();
Expand Down Expand Up @@ -227,60 +222,6 @@ LinesMeasurements TextLayoutManager::measureLines(
AttributedString const &attributedString,
ParagraphAttributes const &paragraphAttributes,
Size size) const {
if (mapBufferSerializationEnabled_) {
return measureLinesMapBuffer(attributedString, paragraphAttributes, size);
}

const jni::global_ref<jobject> &fabricUIManager =
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
static auto measureLines =
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
->getMethod<NativeArray::javaobject(
ReadableMap::javaobject,
ReadableMap::javaobject,
jfloat,
jfloat)>("measureLines");

auto serializedAttributedString = toDynamic(attributedString);

local_ref<ReadableNativeMap::javaobject> attributedStringRNM =
ReadableNativeMap::newObjectCxxArgs(serializedAttributedString);
local_ref<ReadableNativeMap::javaobject> paragraphAttributesRNM =
ReadableNativeMap::newObjectCxxArgs(toDynamic(paragraphAttributes));

local_ref<ReadableMap::javaobject> attributedStringRM = make_local(
reinterpret_cast<ReadableMap::javaobject>(attributedStringRNM.get()));
local_ref<ReadableMap::javaobject> paragraphAttributesRM = make_local(
reinterpret_cast<ReadableMap::javaobject>(paragraphAttributesRNM.get()));

auto array = measureLines(
fabricUIManager,
attributedStringRM.get(),
paragraphAttributesRM.get(),
size.width,
size.height);

auto dynamicArray = cthis(array)->consume();
LinesMeasurements lineMeasurements;
lineMeasurements.reserve(dynamicArray.size());

for (auto const &data : dynamicArray) {
lineMeasurements.push_back(LineMeasurement(data));
}

// Explicitly release smart pointers to free up space faster in JNI tables
attributedStringRM.reset();
attributedStringRNM.reset();
paragraphAttributesRM.reset();
paragraphAttributesRNM.reset();

return lineMeasurements;
}

LinesMeasurements TextLayoutManager::measureLinesMapBuffer(
AttributedString const &attributedString,
ParagraphAttributes const &paragraphAttributes,
Size size) const {
const jni::global_ref<jobject> &fabricUIManager =
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
static auto measureLines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class TextLayoutManager {

void *self_{};
ContextContainer::Shared contextContainer_;
bool mapBufferSerializationEnabled_;
TextMeasureCache measureCache_;
};

Expand Down

0 comments on commit 22b6e1c

Please sign in to comment.