Skip to content

gh-161075: Avoid over-allocation in non-negative int bitwise operations - #161997

Open
ashm-dev wants to merge 1 commit into
python:mainfrom
ashm-dev:gh-161075
Open

ashm-dev wants to merge 1 commit into
python:mainfrom
ashm-dev:gh-161075

Conversation

@ashm-dev

@ashm-dev ashm-dev commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Trim leading zero digits before allocating results for non-negative int & and ^ operations. Return zero and one-digit results directly, and skip redundant normalization for non-negative results.

Add tests for cancellation, unequal operand lengths and digit boundaries.

For a = 1 << (30 * 8192), peak memory traced during a ^ a drops from 32,796 bytes to 0 on a debug build with 30-bit digits.

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

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant