Skip to content

Eliminate temporary std::string copies in CEL protobuf map and Struct lookups. - #2327

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_994548694
Oct 6, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_994548694

Conversation

@copybara-service

Copy link
Copy Markdown

Eliminate temporary std::string copies in CEL protobuf map and Struct lookups.

Previously, looking up or checking presence of a string key in a protobuf map or google.protobuf.Struct allocated or constructed a temporary std::string via StringValue::NativeString() (or std::string(str_key.value())) before populating a google::protobuf::MapKey, even when the key was already backed by a contiguous absl::string_view and only a stack scratch buffer was needed for fragmented cord-backed strings.

This change uses StringValue::ToStringView(&scratch) (and direct absl::string_view in DynamicMap and LookupMapValue) before calling MapKey::SetStringValue, avoiding heap allocations and redundant copies for string-keyed map and google.protobuf.Struct field accesses across:

  • ParsedMapFieldValue::Find and ParsedMapFieldValue::Has
  • ProtoStringMapKeyFromValueConverter
  • FieldBackedMapImpl::LookupMapValue
  • DynamicMap::Has and DynamicMap::operator[] (cel_proto_wrap_util.cc)
  • MapKeyFromQualifier and ProtoQualifyState::ApplySelectQualifiers

@copybara-service
copybara-service Bot force-pushed the test_994548694 branch 2 times, most recently from ee02b96 to 50a59f1 Compare October 6, 2026 22:04
…uct` lookups.

Previously, looking up or checking presence of a string key in a protobuf map or `google.protobuf.Struct` allocated or constructed a temporary `std::string` via `StringValue::NativeString()` (or `std::string(str_key.value())`) before populating a `google::protobuf::MapKey`, even when the key was already backed by a contiguous `absl::string_view` and only a stack scratch buffer was needed for fragmented cord-backed strings.

This change uses `StringValue::ToStringView(&scratch)` (and direct `absl::string_view` in `DynamicMap` and `LookupMapValue`) before calling `MapKey::SetStringValue`, avoiding heap allocations and redundant copies for string-keyed map and `google.protobuf.Struct` field accesses across:
- `ParsedMapFieldValue::Find` and `ParsedMapFieldValue::Has`
- `ProtoStringMapKeyFromValueConverter`
- `FieldBackedMapImpl::LookupMapValue`
- `DynamicMap::Has` and `DynamicMap::operator[]` (`cel_proto_wrap_util.cc`)
- `MapKeyFromQualifier` and `ProtoQualifyState::ApplySelectQualifiers`

PiperOrigin-RevId: 994679246
@copybara-service
copybara-service Bot merged commit 57533e2 into master Oct 6, 2026
3 checks passed
@copybara-service
copybara-service Bot deleted the test_994548694 branch October 6, 2026 22:54
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.

0 participants