You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspired by bpo-44946, I found there were no special shortcuts for shifting operation applied to "medium value" long object. So I modified CPython's VM to accelerate my python project where there is plenty of binary shifting operation. I guess somebody else might also need it.
Could you please show any microbenchmarking results?
xuxinhang commented on Dec 12, 2021
xuxinhangmannequin
MannequinAuthor
More actions
I post a comment to the PR showing its performance improvement. I paste it below. I think the result not bad.
-------------
I use timeit to measure time costs and any other operators or calls are excluded. For each testcase, the former is dcd2796 and the latter is this PR's base 036bbb1.
64-bit Release building. Run in Windows 10 1709 (64-bit)
python -m timeit " i = 1; i <<= 3; i >>= 3" # small value (cost down by 36%) 5000000 loops, best of 5: 92.7 nsec per loop
2000000 loops, best of 5: 145 nsec per loop
python -m timeit " i = 1; i <<= 10; i >>= 10" # medium value (-25%)
2000000 loops, best of 5: 114 nsec per loop
2000000 loops, best of 5: 151 nsec per loop
python -m timeit " i = 1; i <<= 100; i >>= 100" # big value (-12%)
1000000 loops, best of 5: 209 nsec per loop
1000000 loops, best of 5: 238 nsec per loop
Two separate significant improvements have been pushed: thanks, Xinhang Xu!
The original PR also contained a reworking of the general case for right-shifting a negative integer. The current code (in main) for that case does involve some extra allocations, and it ought to be possible to write something that doesn't need to allocate temporary PyLongs.
Activity
xuxinhang commentedon Dec 12, 2021
See its PR.
---------
Inspired by bpo-44946, I found there were no special shortcuts for shifting operation applied to "medium value" long object. So I modified CPython's VM to accelerate my python project where there is plenty of binary shifting operation. I guess somebody else might also need it.
serhiy-storchaka commentedon Dec 12, 2021
Could you please show any microbenchmarking results?
xuxinhang commentedon Dec 12, 2021
I post a comment to the PR showing its performance improvement. I paste it below. I think the result not bad.
-------------
I use timeit to measure time costs and any other operators or calls are excluded. For each testcase, the former is dcd2796 and the latter is this PR's base 036bbb1.
64-bit Release building. Run in Windows 10 1709 (64-bit)
python -m timeit " i = 1; i <<= 3; i >>= 3" # small value (cost down by 36%)
5000000 loops, best of 5: 92.7 nsec per loop
2000000 loops, best of 5: 145 nsec per loop
python -m timeit " i = 1; i <<= 10; i >>= 10" # medium value (-25%)
2000000 loops, best of 5: 114 nsec per loop
2000000 loops, best of 5: 151 nsec per loop
python -m timeit " i = 1; i <<= 100; i >>= 100" # big value (-12%)
1000000 loops, best of 5: 209 nsec per loop
1000000 loops, best of 5: 238 nsec per loop
mdickinson commentedon Dec 27, 2021
New changeset 360fedc by Mark Dickinson in branch 'main':
bpo-46055: Streamline inner loop for right shifts (bpo-30243)
360fedc
mdickinson commentedon Dec 27, 2021
New changeset 3581c7a by Xinhang Xu in branch 'main':
bpo-46055: Speed up binary shifting operators (GH-30044)
3581c7a
mdickinson commentedon Dec 27, 2021
Two separate significant improvements have been pushed: thanks, Xinhang Xu!
The original PR also contained a reworking of the general case for right-shifting a negative integer. The current code (in main) for that case does involve some extra allocations, and it ought to be possible to write something that doesn't need to allocate temporary PyLongs.
gh-90213: Speed up right shifts of negative integers (GH-30277)