Skip to content

Serialize length-prefixed protos once - #27252

Closed
Zaczero wants to merge 1 commit into
protocolbuffers:mainfrom
Zaczero:python-serialize-length-prefixed-once
Closed

Zaczero wants to merge 1 commit into
protocolbuffers:mainfrom
Zaczero:python-serialize-length-prefixed-once

Conversation

@Zaczero

@Zaczero Zaczero commented May 6, 2026

Copy link
Copy Markdown
Contributor

Avoid calling ByteSize() separately in serialize_length_prefixed(). The serialized payload already carries the exact length to prefix, so this keeps behavior intact while avoiding a duplicate serialization-sized pass.

Avoid calling ByteSize() separately in serialize_length_prefixed(). The serialized payload already carries the exact length to prefix, so this keeps behavior intact while avoiding a duplicate serialization-sized pass.

Tested: bazelisk --output_user_root=/tmp/bazel-protobuf test //python:proto_test
@Zaczero
Zaczero requested a review from a team as a code owner May 6, 2026 18:45
@Zaczero
Zaczero requested review from ericsalo and removed request for a team May 6, 2026 18:45
@JasonLunn JasonLunn added the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 13, 2026
@github-actions github-actions Bot removed the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 13, 2026
@JasonLunn JasonLunn added python πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over labels May 13, 2026
@github-actions github-actions Bot removed the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 13, 2026
@JasonLunn JasonLunn added the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 15, 2026
@github-actions github-actions Bot removed the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 15, 2026
@JasonLunn
JasonLunn removed the request for review from ericsalo May 16, 2026 00:19
@JasonLunn JasonLunn added the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 16, 2026
@github-actions github-actions Bot removed the πŸ…°οΈ safe for tests Mark a commit as safe to run presubmits over label May 16, 2026
def test_serialize_length_prefixed_serializes_once(self, message_module):
del message_module

class CountingMessage:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this part hit a snag when we are trying to import it due to pytype checks failing in our internal tests.

Could you rephrase this to

from google.protobuf import message

...

class CountingMessage(message.Message):

instead and rebase? Thanks!

@tonyliaoss

Copy link
Copy Markdown
Member

Let me just patch it manually -- saves a bit of turnaround time. Standby...

In a few moments, if everything goes well, this PR should be auto closed and the original author @Zaczero should still be attributed.

@tonyliaoss

Copy link
Copy Markdown
Member

(Progress can be tracked at #27652)

We will need to run an exhaustive test suite internally, so expect it to take at least 24 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants