Skip to content

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

Merged
mdboom merged 7 commits into
python:mainfrom
mdboom:marshal-slice
Oct 8, 2024
Merged

gh-125063: Emit slices as constants in the bytecode compiler#125064
mdboom merged 7 commits into
python:mainfrom
mdboom:marshal-slice

Conversation

@mdboom

@mdboommdboom commented Oct 7, 2024

Copy link
Copy Markdown
Contributor

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.

Comment threadPython/marshal.c Outdated
Comment threadPython/codegen.c Outdated
Comment threadPython/codegen.c Outdated
mdboomand others added 3 commits October 7, 2024 18:28
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Comment threadPython/codegen.c
@mdboom

Copy link
Copy Markdown
ContributorAuthor

Here are the largest stat changes:

NameBeforeAfterChange
BINARY_SLICE1,144,280,918237,406,036-79.3%
BINARY_SUBSCR2,095,449,8273,002,218,24043.3%
STORE_SLICE162,427,163149,989,760-7.7%
LOAD_CONST18,743,983,32017,819,791,524-4.9%
EXTENDED_ARG481,860,317466,468,380-3.2%
STORE_SUBSCR876,092,109888,534,1411.4%
BUILD_SLICE211,754,494209,634,774-1.0%

@mdboom
mdboom merged commit c6127af into python:mainOct 8, 2024
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 <zintensitydev@gmail.com>
* 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 <mark@hotpy.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@AlexWaygoodAlexWaygood mentioned this pull request Nov 21, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@mdboom@iritkatriel@ZeroIntensity@markshannon