Skip to content

The code generated by DECREF_INPUTS() is often inefficient and complex #131695

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

Closed
brandtbucher opened this issue Mar 24, 2025 · 0 comments · Fixed by #131732
Closed

The code generated by DECREF_INPUTS() is often inefficient and complex #131695

brandtbucher opened this issue Mar 24, 2025 · 0 comments · Fixed by #131732
Assignees
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@brandtbucher
Copy link
Member

For example, this change in Python/bytecodes.c...

diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 66546080b1f..f07c73887bd 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -502,7 +502,7 @@ dummy_func(
             EXIT_IF(!PyList_CheckExact(value_o));
             STAT_INC(TO_BOOL, hit);
             res = PyList_GET_SIZE(value_o) ? PyStackRef_True : PyStackRef_False;
-            DECREF_INPUTS();
+            PyStackRef_CLOSE(value);
         }
 
         inst(TO_BOOL_NONE, (unused/1, unused/2, value -- res)) {

...gives this diff in generated_cases.c.h:

diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 558b0b48cea..b1ddee8d6d7 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -11587,13 +11587,10 @@
             }
             STAT_INC(TO_BOOL, hit);
             res = PyList_GET_SIZE(value_o) ? PyStackRef_True : PyStackRef_False;
+            stack_pointer[-1] = res;
             _PyFrame_SetStackPointer(frame, stack_pointer);
-            _PyStackRef tmp = value;
-            value = res;
-            stack_pointer[-1] = value;
-            PyStackRef_CLOSE(tmp);
+            PyStackRef_CLOSE(value);
             stack_pointer = _PyFrame_GetStackPointer(frame);
-            stack_pointer[-1] = res;
             DISPATCH();
         }

I would expect the code generated for DECREF_INPUTS() to be the same, without the tmp shuffle or redundant store of res after the decrefs have been performed.

@markshannon mentioned that this should be at least partially addressed by GH-131498.

@brandtbucher brandtbucher added 3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants