FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[mypyc] feat: new primitive for `int.bit_length` by BobTheBuidler · Pull Request #19673 · python/mypy · GitHub

Repository navigation

[mypyc] feat: new primitive for int.bit_length - #19673

Merged
JukkaL merged 34 commits into
python:masterfrom
BobTheBuidler:bit-length
Oct 14, 2025
Merged

JukkaL merged 34 commits into
python:masterfrom
BobTheBuidler:bit-length

Conversation

BobTheBuidler commented Aug 16, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

This PR adds a new primitive for int.bit_length and is already ready for review.

Comment thread mypyc/lib-rt/int_ops.c Outdated
Comment thread mypyc/lib-rt/int_ops.c Outdated

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the PR! bit_length can be useful in low-level code, where a generic method call can really slow things down.

Comment thread mypyc/lib-rt/int_ops.c Outdated
Comment thread mypyc/lib-rt/int_ops.c
Comment thread mypyc/test-data/run-integers.test Outdated

Copy link
Copy Markdown
Contributor Author

I'm not entirely sure how to proceed here, I can't think of any reason our use of getattr would lead to segfault behavior where there was none before

Copy link
Copy Markdown
Contributor Author

@JukkaL This one I could definitely use some help with though. I have no idea why 1eb2c7e might cause segfault behavior and I'm inclined to say maybe it's a non-issue and we can mark this test as 64-bit only?

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think I found an issue. Also can you measure the perf difference using a micro-benchmark?

Comment thread mypyc/lib-rt/int_ops.c Outdated
Comment thread mypyc/test-data/run-integers.test Outdated

BobTheBuidler commented Sep 9, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Also can you measure the perf difference using a micro-benchmark?

Will this benchmark suffice? I can deploy this commit hash and compare against 1.18 which I already have benchmarked here

Copy link
Copy Markdown
Contributor Author

Also can you measure the perf difference using a micro-benchmark?

Will this benchmark suffice? I can deploy this commit hash and compare against 1.18 which I already have benchmarked here

1.18 vs this branch

There was a ~6% increase in speed for various permutations of the int_to_big_endian benchmark which includes not only a call to bit_length but a decent bit of other stuff as well

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, looks good now!

JukkaL merged commit 8e57622 into python:master Oct 14, 2025
13 checks passed
BobTheBuidler deleted the bit-length branch October 14, 2025 12:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL