From 219caffb7f7a45325508922e2ff3945c694098b4 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 4 Dec 2026 10:44:12 -0800 Subject: [PATCH] Read attributed string fragments in place when converting to a MapBuffer `toMapBuffer(const AttributedString &)` iterated the fragments by value, so it copied each fragment's string, text attributes and parent `ShadowView`, with its three shared pointers, only to read them. It now iterates by const reference. On an arm64 Android 16 emulator, a benchmark built against `ReactCommon` converted strings with both loops, alternating which ran first. Over three runs, the median time per conversion fell by 1 to 3% for one fragment, 2 to 3% for three short fragments, 7 to 9% for three fragments longer than the small-string buffer, and 2.5 to 3.6% for 20 short fragments. The encoded bytes match. Signed-off-by: James Ide --- .../ReactCommon/react/renderer/attributedstring/conversions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h index 61353692b086..0765bc614c51 100644 --- a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h @@ -1514,7 +1514,7 @@ inline MapBuffer toMapBuffer(const AttributedString &attributedString) auto fragmentsBuilder = MapBufferBuilder(); int index = 0; - for (auto fragment : attributedString.getFragments()) { + for (const auto &fragment : attributedString.getFragments()) { fragmentsBuilder.putMapBuffer(index++, toMapBuffer(fragment)); }