X Tutup
Skip to content

gh-104635: Eliminate redundant STORE_FAST instructions in the compiler#105320

Merged
corona10 merged 2 commits intopython:mainfrom
corona10:gh-104635
Jun 7, 2023
Merged

gh-104635: Eliminate redundant STORE_FAST instructions in the compiler#105320
corona10 merged 2 commits intopython:mainfrom
corona10:gh-104635

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Jun 5, 2023

Benchmarks

import pyperf

runner = pyperf.Runner()
runner.timeit(name="bench dead_store",
              stmt="""
_, _, _, a = 1, 2, 3, 4
""")

Mean +- std dev: [base] 11.7 ns +- 0.2 ns -> [opt] 11.1 ns +- 0.1 ns: 1.05x faster
import pyperf

runner = pyperf.Runner()
runner.timeit(name="bench static swaps",
              stmt="""
_ = f(True, False)
""",
setup="""
def f(x, y):
    a, a = x, y
    return a
""")


Mean +- std dev: [static_base] 27.1 ns +- 0.3 ns -> [static_opt] 26.0 ns +- 0.2 ns: 1.04x faster

@corona10
Copy link
Member Author

corona10 commented Jun 5, 2023

@carljm cc @iritkatriel

Mark's change + dead_store elimination + apply_static_swaps makes 3-5% faster without adding super instruction.

('STORE_FAST', 1, 4),
('POP_TOP', 0, 4),
('RETURN_VALUE', 5)
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 instructions -> 5 instructions

('POP_TOP', 0, 4),
('STORE_FAST', 1, 4),
('RETURN_VALUE', 5)
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 instructions -> 5 instructions

@corona10
Copy link
Member Author

corona10 commented Jun 7, 2023

@carljm Can you please take a look at?

Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.

3 participants

X Tutup