Skip to content

Conversation

ilevkivskyi
Copy link
Member

This is for storing actual bytes objects (not arbitrary sub-buffers). This will be useful for storing various hashes in cache metas, since storing them as hex strings takes twice more space and currently these hashes take a macroscopic part of the cache metas' sizes.

@JukkaL for training purposes you can sync/release this one yourself (if you want to, of course).

@github-actions

This comment has been minimized.

Py_ssize_t size;
_CHECK_READ(data, 1, NULL)
uint8_t first = _READ(data, uint8_t)
if (likely(first != LONG_STR_TAG)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Once we have 2-byte etc. integer formats, it could make sense to use the same integer format here, even if it's slightly non-ideal, so that we can share code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, as I mentioned in other issue I will try to simply code when adding tags for primitive types.

def write_str(data: Buffer, value: str) -> None: ...
def read_str(data: Buffer) -> str: ...
def write_bytes(data: Buffer, value: bytes) -> None: ...
def read_bytes(data: Buffer) -> bytes: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Somewhat meta: what if we'd make all these accept positional arguments only? We could then generate slightly faster wrapper methods for interpreted use cases perhaps (this would affect other methods as well, so the change would be in a separate PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW I am not worried about interpreted performance that much, current code is already relatively efficient, but I am not against if someone else will do this.

@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 fd20f34 into python:master Oct 16, 2025
20 checks passed
@ilevkivskyi ilevkivskyi deleted the add-bytes-librt-internal branch October 16, 2025 11:54
@ilevkivskyi
Copy link
Member Author

ilevkivskyi commented Oct 16, 2025

@JukkaL so do you want to release this one yourself? The steps are:

  • Clone librt repo
  • Run the sync script
  • Bump the version in pyproject.toml (this is a feature, so should be 0.3.0 I guess)
  • Update smoke_tests.py (this is optional but advised if there are new features)
  • Commit and push (pushing directly to master is fine)
  • Wait until all builds complete successfully (no release is triggered yet)
  • If everything is fine, create/push the tag
  • Then go to "Actions" tab -> select "Build wheels" on the left
  • Click "Run workflow" and choose the newly created tag in drop-down, this will build and upload the wheels
  • After workflow is done, verify that pip install -U librt installs the new version from PyPI

If you don't have time, I can do it myself. But from my experience it is very fast, whole process takes ~15min

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 16, 2025

Okay, I'll try to follow the steps (today or tomorrow probably).

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 16, 2025

I'm not sure what's the right way build and install the library and run tests locally. I think this should be documented as well -- I tried a few obvious things but they didn't work.

@ilevkivskyi
Copy link
Member Author

Oh I think pip install -U ./lib-rt followed by pytest smoke_tests.py should work.

@ilevkivskyi
Copy link
Member Author

ilevkivskyi commented Oct 16, 2025

To give some context on why it is made that way, it is because I wanted the part that is synced to be located in a directory, to not clutter the top level, but since this includes setup.py you need to run the install as I said above.

Btw don't worry if it will say Successfully installed UNKNOWN-0.0.0, just be sure to do this in some separate venv, not in the same one where you run or develop mypy.

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 17, 2025

Now the 0.3.0 release of librt is up, with these changes. I'll create a PR to add more detailed release instructions to the librt repo.

JukkaL added a commit to mypyc/librt that referenced this pull request Oct 17, 2025
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