Skip to content

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.

@mdboom mdboom requested a review from iritkatriel October 8, 2024 12:51
@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