Skip to content

[mypyc] Add write_i16_le and read_i16_le to librt.strings#20745

Merged
JukkaL merged 11 commits intomasterfrom
librt-strings-read-i16
Feb 5, 2026
Merged

[mypyc] Add write_i16_le and read_i16_le to librt.strings#20745
JukkaL merged 11 commits intomasterfrom
librt-strings-read-i16

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 5, 2026

These are experimental optimized primitives for reading/writing 16-bit binary integers. I'll later add support for other integer sizes and floats, and big endian formats.

The main optimization here is to inline the hot paths of these functions. Also the api is optimized for performance and not really ergonomics, though I don't think the ergonomics are particularly bad. When reading, the caller needs to keep track of the index to the bytes object, and negative indexes aren't supported, but the latter doesn't seem really useful for these kinds of primitives.

In a microbenchmark, these can be dozens of times faster than using stdlib struct (when compiled).

It may still be possible to further optimize performance, but these seem already pretty good.

I used coding agent assist but through small human reviewed increments.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

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

@JukkaL JukkaL merged commit 2f9d807 into master Feb 5, 2026
23 checks passed
@JukkaL JukkaL deleted the librt-strings-read-i16 branch February 5, 2026 12:31
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