Skip to content

Split mp_binary_op into inlinable and non-inlinable variants. - #25

Merged
ltratt merged 1 commit into
ykjit:masterfrom
ltratt:split_mp_binary_op
Jul 29, 2026
Merged

Split mp_binary_op into inlinable and non-inlinable variants.#25
ltratt merged 1 commit into
ykjit:masterfrom
ltratt:split_mp_binary_op

Conversation

@ltratt

@ltratt ltratt commented Jul 28, 2026

Copy link
Copy Markdown

mp's normal mp_binary_op inlines iterator comparisons for contains: the resultant while loop prevents mp_binary_op from being inlined in a trace. This commit breaks out the arbitrary-length while loop into a separate function: normal binary operations are now inlined, but list (etc.) comparisons aren't. The one exception is tuples: those are inlined (and therefore unrolled), because they are almost always small and fixed in size.

This speeds nearly everything up, if only by a bit:

BigLoop/ykmp/1000000000  227746 ±  976  136731 ±    5   0.60  39.96% faster
Sieve/ykmp/3000           19497 ±   59   15379 ±   79   0.79  21.12% faster
Queens/ykmp/1000          70252 ±  557   66450 ±  111   0.95  5.41% faster
List/ykmp/1500            62093 ±  626   58845 ± 1500   0.95  5.23% faster
Towers/ykmp/600          153793 ±  312  145922 ±  541   0.95  5.12% faster
Richards/ykmp/100        355874 ±  361  337834 ±  693   0.95  5.07% faster
Bounce/ykmp/1500         122221 ±  811  117012 ± 1106   0.96  4.26% faster
Permute/ykmp/1000        133177 ±  171  128087 ±  329   0.96  3.82% faster
CD/ykmp/250              209803 ± 1146  202455 ±  381   0.96  3.50% faster
NBody/ykmp/250000        112451 ±   92  113991 ± 1165   1.01  1.37% slower
Storage/ykmp/1000        112431 ±31069   88203 ±  293   0.78  indistinguishable
Mandelbrot/ykmp/500       44276 ± 1156   42130 ± 1316   0.95  indistinguishable

mp's normal `mp_binary_op` inlines iterator comparisons for `contains`:
the resultant `while` loop prevents `mp_binary_op` from being inlined in
a trace. This commit breaks out the arbitrary-length `while` loop into a
separate function: normal binary operations are now inlined, but list
(etc.) comparisons aren't. The one exception is tuples: those _are_
inlined (and therefore unrolled), because they are almost always small
and fixed in size.

This speeds nearly everything up, if only by a bit:

```
BigLoop/ykmp/1000000000  227746 ±  976  136731 ±    5   0.60  39.96% faster
Sieve/ykmp/3000           19497 ±   59   15379 ±   79   0.79  21.12% faster
Queens/ykmp/1000          70252 ±  557   66450 ±  111   0.95  5.41% faster
List/ykmp/1500            62093 ±  626   58845 ± 1500   0.95  5.23% faster
Towers/ykmp/600          153793 ±  312  145922 ±  541   0.95  5.12% faster
Richards/ykmp/100        355874 ±  361  337834 ±  693   0.95  5.07% faster
Bounce/ykmp/1500         122221 ±  811  117012 ± 1106   0.96  4.26% faster
Permute/ykmp/1000        133177 ±  171  128087 ±  329   0.96  3.82% faster
CD/ykmp/250              209803 ± 1146  202455 ±  381   0.96  3.50% faster
NBody/ykmp/250000        112451 ±   92  113991 ± 1165   1.01  1.37% slower
Storage/ykmp/1000        112431 ±31069   88203 ±  293   0.78  indistinguishable
Mandelbrot/ykmp/500       44276 ± 1156   42130 ± 1316   0.95  indistinguishable
```
@Pavel-Durov
Pavel-Durov added this pull request to the merge queue Jul 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 29, 2026
@Pavel-Durov

Copy link
Copy Markdown

Looks like test failed:

11:49:04 2 tests failed: basics/int_big_mul.py thread/thread_lock4_intbig.py

@ltratt

ltratt commented Jul 29, 2026

Copy link
Copy Markdown
Author

Yes, currently investigating. This is probably a deopt bug but not 100% sure yet.

@ltratt
ltratt added this pull request to the merge queue Jul 29, 2026
Merged via the queue into ykjit:master with commit 19b7cd9 Jul 29, 2026
2 checks passed
@ltratt
ltratt deleted the split_mp_binary_op branch July 29, 2026 16:11
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