10000 The code generated by `DECREF_INPUTS()` is often inefficient and complex · Issue #131695 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
The code generated by DECREF_INPUTS() is often inefficient and complex #131695
Closed
@brandtbucher

Description

@brandtbucher

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.

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0