gh-151289: specialize shrinking int subtraction#151290
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
1 similar comment
This comment was marked as resolved.
This comment was marked as resolved.
skirpichev
left a comment
There was a problem hiding this comment.
As I said in the issue thread, I'm not sure if this worth code complications.
Other than this, few remarks:
- Probably, you should split this pr into several. For instance, separate freelists addition looks unrelated.
- I don't think you should add benchmark script to the sources. Just include this code in pr description, for example.
sure, I'll revert and update the numbers, though I think @peendebak mentioned he had a independent freelist PR somewhere so I'll just drop mine entirely.
sure,though it's standard practices to have a |
|
Do not click the "Update branch" button without a good reason because it notifies everyone watching the PR that there are new changes, when there are not, and it uses up limited CI resources. |
|
I don't see any speedup, and in fact see a significant slowdown on the bigint path: The benchmark scripts in the original issue is not really measuring the operation I feel, so I modified it: |
|
There’s a small bug in the benchmark script in that comment: the two subtraction cases are still doing def bench_sub_compact(loops):
...
for _ in it:
a + b
def bench_sub_wide(loops):
...
for _ in it:
a + bThose should be |
This narrows the old wide-int experiment down to a single targeted optimization for
intsubtraction.When both operands are exact
intobjects, have the same sign, have the same top digit, and are 2- or 3-digitPyLongs on 30-bit builds, subtraction often produces a smaller result. This change teachesBINARY_OP_SUBTRACT_INTto specialize that case and compute the result directly, instead of falling back to the generic long subtraction path.