Skip to content

Size the MapBuffer payload before writing each list - #60536

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/mapbuffer-list-sizing
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/mapbuffer-list-sizing

Conversation

@ide

@ide ide commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

putMapBufferList grows its payload vector for each child. Sum the child sizes and their length prefixes, resize the vector once, then write the list in the existing format. The vector still grows geometrically across successive lists.

Changelog:

[INTERNAL] [CHANGED] - Resize the MapBuffer payload once per list.

Test Plan:

The C++ MapBufferTest suite passes. One optimized Apple arm64 binary compares both serializers. Median retired instructions per list fall from 4,372 to 2,757 for five children and from 21,463 to 11,911 for 100 children. When one MapBufferBuilder writes 128 consecutive two-child lists, the median falls from 399 to 334 instructions per list. Encoded sizes and checksums match.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@ide
ide force-pushed the @ide/mapbuffer-list-sizing branch 2 times, most recently from 653909a to 0c9bae9 Compare December 4, 2026 12:35
@ide
ide marked this pull request as ready for review December 4, 2026 14:37
Comment on lines +146 to +152
auto position = offset;
for (const auto& mapBuffer : mapBufferList) {
const auto mapBufferSize = static_cast<int32_t>(mapBuffer.size());
memcpy(dynamicData_.data() + position, &mapBufferSize, INT_SIZE);
position += INT_SIZE;
memcpy(dynamicData_.data() + position, mapBuffer.data(), mapBufferSize);
position += mapBufferSize;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: keep the explicit inline values of + pos and + pos + INT_SIZE so these don't become instruction dependencies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

position is never read after this, so the increment is wasted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2b61eaa: both copies use position and position + INT_SIZE directly, and position advances once per child. The benchmark in the test plan is updated, and the numbers are slightly lower than before.

`putMapBufferList` grows its payload vector for each child. Sum the child sizes and their length prefixes, resize the vector once, then write the list in the existing format. The vector still grows geometrically across successive lists.

The C++ `MapBufferTest` suite passes. One optimized Apple arm64 binary compares both serializers. Median retired instructions per list fall from 4,372 to 2,757 for five children and from 21,463 to 11,911 for 100 children. When one `MapBufferBuilder` writes 128 consecutive two-child lists, the median falls from 399 to 334 instructions per list. Encoded sizes and checksums match.

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/mapbuffer-list-sizing branch from 0c9bae9 to 2b61eaa Compare December 4, 2026 19:13
@meta-codesync

meta-codesync Bot commented Dec 4, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D136355128.

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

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants