Skip to content

perf(grpc-js): lazily allocate Metadata opaqueData map - #3095

Merged
murgatroid99 merged 2 commits into
grpc:masterfrom
olavloite:lazy-metadata-opaque-map
Sep 25, 2026
Merged

murgatroid99 merged 2 commits into
grpc:masterfrom
olavloite:lazy-metadata-opaque-map

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Every Metadata instance previously allocated a Map for opaqueData in its constructor, even though opaqueData is only used in specific scenarios like caching parsed ORCA load reports on trailers.

On high-throughput RPC paths where multiple Metadata instances are created per call, this eager allocation resulted in unnecessary heap allocation and GC pressure.

Changes:

  • Make Metadata.prototype.opaqueData optional and lazily instantiate the Map on the first setOpaque() call.
  • Use optional chaining in getOpaque() when reading from opaqueData.
  • Preserve existing clone() and constructor behavior to maintain exact compatibility.
  • Add unit tests covering lazy allocation, key updates, value types, and cloned instance behavior.

Every Metadata instance previously allocated a Map for opaqueData in its
constructor, even though opaqueData is only used in specific scenarios like
caching parsed ORCA load reports on trailers.

On high-throughput RPC paths where multiple Metadata instances are created
per call, this eager allocation resulted in unnecessary heap allocation and
GC pressure.

Changes:
- Make Metadata.prototype.opaqueData optional and lazily instantiate the
  Map on the first setOpaque() call.
- Use optional chaining in getOpaque() when reading from opaqueData.
- Preserve existing clone() and constructor behavior to maintain exact
  compatibility.
- Add unit tests covering lazy allocation, key updates, value types, and
  cloned instance behavior.
@murgatroid99
murgatroid99 merged commit 0f7ddd8 into grpc:master Sep 25, 2026
8 of 10 checks passed
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.

3 participants