Skip to content

Make IPC framing more efficient#20793

Merged
ilevkivskyi merged 2 commits intopython:masterfrom
ilevkivskyi:use-base64
Feb 12, 2026
Merged

Make IPC framing more efficient#20793
ilevkivskyi merged 2 commits intopython:masterfrom
ilevkivskyi:use-base64

Conversation

@ilevkivskyi
Copy link
Member

This is not important now, but it will be important when we will start sending serialized ASTs over IPC, using stdlib base64 can easily add 0.5-1ms per file round-trip overhead, which is a lot.

Initially I waned to use librt.base64, but ultimately simply switched to framing with a fixed size header. I am still using librt.base64 in few places where performance doesn't really matter, because why not.

Btw I noticed we have very few mypyc primitives for bytearray, probably we should add more, added comment in mypyc/mypyc#644

@github-actions

This comment has been minimized.

bdata = self.buffer[HEADER_SIZE : HEADER_SIZE + self.message_size]
self.buffer = self.buffer[HEADER_SIZE + self.message_size :]
self.message_size = None
return bytes(bdata)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something like bytes(memoryview(self.buffer)[slice]) might save this copy right? (In 3.15 we can use bytearray.take_bytes)

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. Yeah, let's do this. Btw it would be great if mypyc could support this as well. I don't think we have any primitives for memoryview.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi ilevkivskyi merged commit c67a479 into python:master Feb 12, 2026
23 checks passed
@ilevkivskyi ilevkivskyi deleted the use-base64 branch February 12, 2026 23:20
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.

2 participants