Skip to content

Add IntBuffer and DoubleBuffer entry types to MapBuffer (#57359)#57359

Open
javache wants to merge 2 commits into
react:mainfrom
javache:export-D109848476
Open

Add IntBuffer and DoubleBuffer entry types to MapBuffer (#57359)#57359
javache wants to merge 2 commits into
react:mainfrom
javache:export-D109848476

Conversation

@javache

@javache javache commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary:

Adds two new MapBuffer entry types, IntBuffer and DoubleBuffer, for storing homogeneous arrays of ints and doubles compactly in the dynamic data section. Unlike Map / map lists, these carry no per-element key/type overhead: a batch of N values costs ~N*elementSize bytes plus a single 4-byte count prefix instead of N 12-byte buckets. The bucket value holds the offset of the array within the dynamic data section.

Covers the full surface: the C++ reader (MapBuffer::getIntBuffer / getDoubleBuffer), the C++ builder (MapBufferBuilder::putIntBuffer / putDoubleBuffer), and the Kotlin reader API (MapBuffer.getIntBuffer / getDoubleBuffer, Entry.intBufferValue / doubleBufferValue). The DataType enum gains IntBuffer = 6 and DoubleBuffer = 7, kept in sync across C++ and Kotlin.

Changelog:
[General][Added] - Add IntBuffer and DoubleBuffer entry types to MapBuffer for compact homogeneous int/double arrays

Reviewed By: zeyap

Differential Revision: D109848476

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 29, 2026
@meta-codesync

meta-codesync Bot commented Jun 29, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109848476.

@meta-codesync meta-codesync Bot changed the title Add IntBuffer and DoubleBuffer entry types to MapBuffer Add IntBuffer and DoubleBuffer entry types to MapBuffer (#57359) Jun 29, 2026
javache added a commit to javache/react-native that referenced this pull request Jun 29, 2026
Summary:

Adds two new MapBuffer entry types, `IntBuffer` and `DoubleBuffer`, for storing homogeneous arrays of ints and doubles compactly in the dynamic data section. Unlike `Map` / map lists, these carry no per-element key/type overhead: a batch of N values costs ~N*elementSize bytes plus a single 4-byte count prefix instead of N 12-byte buckets. The bucket value holds the offset of the array within the dynamic data section.

Covers the full surface: the C++ reader (`MapBuffer::getIntBuffer` / `getDoubleBuffer`), the C++ builder (`MapBufferBuilder::putIntBuffer` / `putDoubleBuffer`), and the Kotlin reader API (`MapBuffer.getIntBuffer` / `getDoubleBuffer`, `Entry.intBufferValue` / `doubleBufferValue`). The `DataType` enum gains `IntBuffer = 6` and `DoubleBuffer = 7`, kept in sync across C++ and Kotlin.

Changelog:
[General][Added] - Add `IntBuffer` and `DoubleBuffer` entry types to MapBuffer for compact homogeneous int/double arrays

Differential Revision: D109848476
@javache javache force-pushed the export-D109848476 branch 2 times, most recently from d49129e to 15e7022 Compare July 1, 2026 11:46
javache added a commit to javache/react-native that referenced this pull request Jul 1, 2026
Summary:

Adds two new MapBuffer entry types, `IntBuffer` and `DoubleBuffer`, for storing homogeneous arrays of ints and doubles compactly in the dynamic data section. Unlike `Map` / map lists, these carry no per-element key/type overhead: a batch of N values costs ~N*elementSize bytes plus a single 4-byte count prefix instead of N 12-byte buckets. The bucket value holds the offset of the array within the dynamic data section.

Covers the full surface: the C++ reader (`MapBuffer::getIntBuffer` / `getDoubleBuffer`), the C++ builder (`MapBufferBuilder::putIntBuffer` / `putDoubleBuffer`), and the Kotlin reader API (`MapBuffer.getIntBuffer` / `getDoubleBuffer`, `Entry.intBufferValue` / `doubleBufferValue`). The `DataType` enum gains `IntBuffer = 6` and `DoubleBuffer = 7`, kept in sync across C++ and Kotlin.

Changelog:
[General][Added] - Add `IntBuffer` and `DoubleBuffer` entry types to MapBuffer for compact homogeneous int/double arrays

Differential Revision: D109848476
javache added 2 commits July 1, 2026 06:37
…eact#57398)

Summary:

`buckets_.data()` and `dynamicData_.data()` return `nullptr` when the vector is empty, and glibc marks `memcpy`'s src argument as `nonnull`. Passing `nullptr` is UB even with a size of 0, which trips UBSan halt-on-error on any MapBuffer that has no buckets (`EMPTY()`) or no dynamic-data entries (scalar-only maps). Guard both memcpys with an empty check.

Changelog:
[General][Fixed] - Avoid `memcpy(_, nullptr, 0)` UB in `MapBufferBuilder::build` for empty / scalar-only MapBuffers

Reviewed By: cortinico

Differential Revision: D110316404
Summary:

Adds two new MapBuffer entry types, `IntBuffer` and `DoubleBuffer`, for storing homogeneous arrays of ints and doubles compactly in the dynamic data section. Unlike `Map` / map lists, these carry no per-element key/type overhead: a batch of N values costs ~N*elementSize bytes plus a single 4-byte count prefix instead of N 12-byte buckets. The bucket value holds the offset of the array within the dynamic data section.

Covers the full surface: the C++ reader (`MapBuffer::getIntBuffer` / `getDoubleBuffer`), the C++ builder (`MapBufferBuilder::putIntBuffer` / `putDoubleBuffer`), and the Kotlin reader API (`MapBuffer.getIntBuffer` / `getDoubleBuffer`, `Entry.intBufferValue` / `doubleBufferValue`). The `DataType` enum gains `IntBuffer = 6` and `DoubleBuffer = 7`, kept in sync across C++ and Kotlin.

Changelog:
[General][Added] - Add `IntBuffer` and `DoubleBuffer` entry types to MapBuffer for compact homogeneous int/double arrays

Reviewed By: zeyap

Differential Revision: D109848476
@javache javache force-pushed the export-D109848476 branch from 15e7022 to 28be5ba Compare July 1, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant