GeezerVison is showing github.com — GH-128914: Remove conditional stack effects from `bytecodes.c` and the code generators by markshannon · Pull Request #128918 · python/cpython
Conversation
markshannon
commented
Jan 16, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This PR:
- Removes support for conditional stack effects. Variable stack effects are still supported
- Splits
LOAD_ATTR into LOAD_ATTR and LOAD_METHOD. The specializations split neatly between the two, so no new specializations are needed.
- Splits
LOAD_SUPER_ATTR into LOAD_SUPER_ATTR and LOAD_SUPER_METHOD. This is a bit wasteful as LOAD_SUPER_ATTR is quite rare and it needs an additional instrumented instruction as well. It might be worth trying to merge them somehow in another PR later on but doing so now would complicate this PR unnecessarily.
Performance is 0.4% slower which is, I think, acceptable given the potential speedups from top of stack caching.
The slowdown appears to be mostly a result of the large number of extra PUSH_NULL instructions required. There are ways to mitigate this, but not in this PR.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This will conflict with #128722, so that PR should be merged first.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice to see so much red.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…to no-conditional-stack-effects
colesbury
commented
Jan 21, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Hi @markshannon, this PR introduced performance regressions in the free threading build:
I think that the multithreading scaling issue is because previously module.foo() used to specialize to _LOAD_ATTR_MODULE_FROM_KEYS, but with this PR it now uses the unspecialized LOAD_METHOD. _LOAD_ATTR_MODULE_FROM_KEYS supports deferred reference counting, but LOAD_METHOD does not. That may be related to the single-threaded perf regression too, but I'm not sure.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@colesbury IIRC I was the one that merged these two instructions together. Based on my memory at the time LOAD_ATTR does cover LOAD_METHOD in some cases, so I'm not surprised theres a perf regression.
I'm surprised by your benchmark results though. If you look into them, it says things like nbody, spectralnorm slowed down. However, these dont use LOAD_ATTR at all?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
colesbury
added a commit
to colesbury/cpython
that referenced
this pull request
Jan 22, 2025
…odes.c` and the code generators (pythonGH-128918)"
The commit introduced a large performance regression in the free threading build.
This reverts commit ab61d3f.
colesbury
added a commit
to colesbury/cpython
that referenced
this pull request
Jan 22, 2025
…odes.c` and the code generators (pythonGH-128918)"
The commit introduced a ~2.5-3% regression in the free threading build.
This reverts commit ab61d3f.
diegorusso
commented
Jan 23, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Not 100% sure, but this PR makes the test test.test__opcode failing if CPython is compiled with --enable-pystats
$ ./python -mtest test.test__opcode
Using random seed: 2376878257
0:00:00 load avg: 0.20 Run 1 test sequentially in a single process
0:00:00 load avg: 0.20 [1/1] test.test__opcode
test test.test__opcode failed -- Traceback (most recent call last):
File "/home/dierus01/work/ce-sw/repos/cpython/Lib/test/test__opcode.py", line 131, in test_specialization_stats
self.assertCountEqual(stats.keys(), specialized_opcodes)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Element counts were not equal:
First has 0, Second has 1: 'load_super_method'
First has 0, Second has 1: 'load_method'
test.test__opcode failed (1 failure)
== Tests result: FAILURE ==
1 test failed:
test.test__opcode
Total duration: 24 ms
Total tests: run=7 failures=1
Total test files: run=1/1 failed=1
Result: FAILURE
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
diegorusso
commented
Jan 23, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
OK, this fixes it!
$ git diff
diff --git a/Python/specialize.c b/Python/specialize.c
index eb599028cef..bc44b776026 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -111,6 +111,8 @@ _Py_GetSpecializationStats(void) {
int err = 0;
err += add_stat_dict(stats, CONTAINS_OP, "contains_op");
err += add_stat_dict(stats, LOAD_SUPER_ATTR, "load_super_attr");
+ err += add_stat_dict(stats, LOAD_SUPER_METHOD, "load_super_method");
+ err += add_stat_dict(stats, LOAD_METHOD, "load_method");
err += add_stat_dict(stats, LOAD_ATTR, "load_attr");
err += add_stat_dict(stats, LOAD_GLOBAL, "load_global");
err += add_stat_dict(stats, BINARY_SUBSCR, "binary_subscr");
$ ./python -mtest test.test__opcode
Using random seed: 911391223
0:00:00 load avg: 0.31 Run 1 test sequentially in a single process
0:00:00 load avg: 0.31 [1/1] test.test__opcode
== Tests result: SUCCESS ==
1 test OK.
Total duration: 19 ms
Total tests: run=7
Total test files: run=1/1
Result: SUCCESS
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
diegorusso
commented
Jan 23, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
This has been reverted for now: #129202 No need to push the fix.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
ericsnowcurrently
Awaiting requested review from ericsnowcurrently
ericsnowcurrently is a code owner
Fidget-Spinner
Awaiting requested review from Fidget-Spinner
Fidget-Spinner is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|