Skip to content

Read attributed string fragments in place when converting to a MapBuffer - #60567

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/attributed-string-fragment-ref
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/attributed-string-fragment-ref

Conversation

@ide

@ide ide commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Summary:

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.

Changelog:

[INTERNAL] [CHANGED] - Read attributed string fragments in place when converting to a MapBuffer.

Test Plan:

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.

`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 <ide@expo.dev>
@ide
ide marked this pull request as ready for review December 4, 2026 20:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant