Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-125063: Emit slices as constants in the bytecode compiler #125064

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Oct 7, 2024

This emits slices as constants in the compiler (when the slices only contain constant members).

I measured a 10% speedup on the cavity_flow benchmark in npbench, which not surprisingly uses a lot of slices, but this kind of code is fairly idiomatic for Numpy. (EDIT: The benchmark as a standalone script)

This does measure as are 1% slower on pyperformance, but that seems largely due to unpack_sequence. I'm going to rerun on more platforms, and also collect stats, since I would expect a measurable reduction in instructions executed.

Python/marshal.c Outdated Show resolved Hide resolved
Python/codegen.c Outdated Show resolved Hide resolved
Python/codegen.c Outdated Show resolved Hide resolved
@mdboom
Copy link
Contributor Author

mdboom commented Oct 8, 2024

Here are the largest stat changes:

Name Before After Change
BINARY_SLICE 1,144,280,918 237,406,036 -79.3%
BINARY_SUBSCR 2,095,449,827 3,002,218,240 43.3%
STORE_SLICE 162,427,163 149,989,760 -7.7%
LOAD_CONST 18,743,983,320 17,819,791,524 -4.9%
EXTENDED_ARG 481,860,317 466,468,380 -3.2%
STORE_SUBSCR 876,092,109 888,534,141 1.4%
BUILD_SLICE 211,754,494 209,634,774 -1.0%

@mdboom mdboom merged commit c6127af into python:main Oct 8, 2024
37 checks passed
efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull request Oct 9, 2024
…ython#125064)

* Make slices marshallable

* Emit slices as constants

* Update Python/marshal.c

Co-authored-by: Peter Bierma <[email protected]>

* Refactor codegen_slice into two functions so it
always has the same net effect

* Fix for free-threaded builds

* Simplify marshal loading of slices

* Only return SUCCESS/ERROR from codegen_slice

---------

Co-authored-by: Mark Shannon <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants