Skip to content

Commit

Permalink
Avoid boxing when serializing primitive lists in CodedOutputStreamWriter
Browse files Browse the repository at this point in the history
Previously, these List.get methods returned Object, forcing boxing, and (if not in the primitive's box cache) allocation, with all the cost that entails.

I've taken the approach of duplicating methods to specialise for primitives, like BinaryWriter does for non-lite protos.

I initially considered checking the class of the list on every iteration of the
loop, but that feels wasteful, when we can
check it once at the start of the loop. This also means we have the same
behaviour as serverside protos. At the cost of a few more methods, but
hopefully they're trivially inlineable, so hopefully leading to a small dex increase without really increasing the method count.

Given this is a public API, I don't think we can remove the List<Long> overloads either.

PiperOrigin-RevId: 627183583
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Apr 22, 2024
1 parent d1cf09a commit eaee04d
Showing 1 changed file with 416 additions and 1 deletion.
Loading

0 comments on commit eaee04d

Please sign in to comment.