Skip to content

Commit a3d8c05

Browse files
authored
GH-123197: Only count an instruction as deferred if it hasn't deopted first. (GH-123222)
Only count an instruction as deferred if hasn't deopted first.
1 parent 3d7b1a5 commit a3d8c05

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
384384
} \
385385
} while (0)
386386
#define RARE_EVENT_STAT_INC(name) do { if (_Py_stats) _Py_stats->rare_event_stats.name++; } while (0)
387+
#define OPCODE_DEFERRED_INC(opname) do { if (_Py_stats && opcode == opname) _Py_stats->opcode_stats[opname].specialization.deferred++; } while (0)
387388

388389
// Export for '_opcode' shared extension
389390
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
@@ -405,6 +406,7 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
405406
#define OPT_ERROR_IN_OPCODE(opname) ((void)0)
406407
#define OPT_HIST(length, name) ((void)0)
407408
#define RARE_EVENT_STAT_INC(name) ((void)0)
409+
#define OPCODE_DEFERRED_INC(opname) ((void)0)
408410
#endif // !Py_STATS
409411

410412
// Utility functions for reading/writing 32/64-bit values in the inline caches.

Python/bytecodes.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ dummy_func(
350350
_Py_Specialize_ToBool(value, next_instr);
351351
DISPATCH_SAME_OPARG();
352352
}
353-
STAT_INC(TO_BOOL, deferred);
353+
OPCODE_DEFERRED_INC(TO_BOOL);
354354
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
355355
#endif /* ENABLE_SPECIALIZATION */
356356
}
@@ -651,7 +651,7 @@ dummy_func(
651651
_Py_Specialize_BinarySubscr(container, sub, next_instr);
652652
DISPATCH_SAME_OPARG();
653653
}
654-
STAT_INC(BINARY_SUBSCR, deferred);
654+
OPCODE_DEFERRED_INC(BINARY_SUBSCR);
655655
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
656656
#endif /* ENABLE_SPECIALIZATION */
657657
}
@@ -835,7 +835,7 @@ dummy_func(
835835
_Py_Specialize_StoreSubscr(container, sub, next_instr);
836836
DISPATCH_SAME_OPARG();
837837
}
838-
STAT_INC(STORE_SUBSCR, deferred);
838+
OPCODE_DEFERRED_INC(STORE_SUBSCR);
839839
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
840840
#endif /* ENABLE_SPECIALIZATION */
841841
}
@@ -1048,7 +1048,7 @@ dummy_func(
10481048
_Py_Specialize_Send(receiver, next_instr);
10491049
DISPATCH_SAME_OPARG();
10501050
}
1051-
STAT_INC(SEND, deferred);
1051+
OPCODE_DEFERRED_INC(SEND);
10521052
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
10531053
#endif /* ENABLE_SPECIALIZATION */
10541054
}
@@ -1314,7 +1314,7 @@ dummy_func(
13141314
_Py_Specialize_UnpackSequence(seq, next_instr, oparg);
13151315
DISPATCH_SAME_OPARG();
13161316
}
1317-
STAT_INC(UNPACK_SEQUENCE, deferred);
1317+
OPCODE_DEFERRED_INC(UNPACK_SEQUENCE);
13181318
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
13191319
#endif /* ENABLE_SPECIALIZATION */
13201320
(void)seq;
@@ -1386,7 +1386,7 @@ dummy_func(
13861386
_Py_Specialize_StoreAttr(owner, next_instr, name);
13871387
DISPATCH_SAME_OPARG();
13881388
}
1389-
STAT_INC(STORE_ATTR, deferred);
1389+
OPCODE_DEFERRED_INC(STORE_ATTR);
13901390
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
13911391
#endif /* ENABLE_SPECIALIZATION */
13921392
}
@@ -1503,7 +1503,7 @@ dummy_func(
15031503
_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name);
15041504
DISPATCH_SAME_OPARG();
15051505
}
1506-
STAT_INC(LOAD_GLOBAL, deferred);
1506+
OPCODE_DEFERRED_INC(LOAD_GLOBAL);
15071507
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
15081508
#endif /* ENABLE_SPECIALIZATION */
15091509
}
@@ -1836,7 +1836,7 @@ dummy_func(
18361836
_Py_Specialize_LoadSuperAttr(global_super_st, class_st, next_instr, load_method);
18371837
DISPATCH_SAME_OPARG();
18381838
}
1839-
STAT_INC(LOAD_SUPER_ATTR, deferred);
1839+
OPCODE_DEFERRED_INC(LOAD_SUPER_ATTR);
18401840
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
18411841
#endif /* ENABLE_SPECIALIZATION */
18421842
}
@@ -1953,7 +1953,7 @@ dummy_func(
19531953
_Py_Specialize_LoadAttr(owner, next_instr, name);
19541954
DISPATCH_SAME_OPARG();
19551955
}
1956-
STAT_INC(LOAD_ATTR, deferred);
1956+
OPCODE_DEFERRED_INC(LOAD_ATTR);
19571957
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
19581958
#endif /* ENABLE_SPECIALIZATION */
19591959
}
@@ -2284,7 +2284,7 @@ dummy_func(
22842284
_Py_Specialize_CompareOp(left, right, next_instr, oparg);
22852285
DISPATCH_SAME_OPARG();
22862286
}
2287-
STAT_INC(COMPARE_OP, deferred);
2287+
OPCODE_DEFERRED_INC(COMPARE_OP);
22882288
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
22892289
#endif /* ENABLE_SPECIALIZATION */
22902290
}
@@ -2405,7 +2405,7 @@ dummy_func(
24052405
_Py_Specialize_ContainsOp(right, next_instr);
24062406
DISPATCH_SAME_OPARG();
24072407
}
2408-
STAT_INC(CONTAINS_OP, deferred);
2408+
OPCODE_DEFERRED_INC(CONTAINS_OP);
24092409
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
24102410
#endif /* ENABLE_SPECIALIZATION */
24112411
}
@@ -2720,7 +2720,7 @@ dummy_func(
27202720
_Py_Specialize_ForIter(iter, next_instr, oparg);
27212721
DISPATCH_SAME_OPARG();
27222722
}
2723-
STAT_INC(FOR_ITER, deferred);
2723+
OPCODE_DEFERRED_INC(FOR_ITER);
27242724
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
27252725
#endif /* ENABLE_SPECIALIZATION */
27262726
}
@@ -3189,7 +3189,7 @@ dummy_func(
31893189
_Py_Specialize_Call(callable, next_instr, oparg + !PyStackRef_IsNull(self_or_null));
31903190
DISPATCH_SAME_OPARG();
31913191
}
3192-
STAT_INC(CALL, deferred);
3192+
OPCODE_DEFERRED_INC(CALL);
31933193
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
31943194
#endif /* ENABLE_SPECIALIZATION */
31953195
}
@@ -4196,7 +4196,7 @@ dummy_func(
41964196
_Py_Specialize_CallKw(callable, next_instr, oparg + !PyStackRef_IsNull(self_or_null));
41974197
DISPATCH_SAME_OPARG();
41984198
}
4199-
STAT_INC(CALL_KW, deferred);
4199+
OPCODE_DEFERRED_INC(CALL_KW);
42004200
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
42014201
#endif /* ENABLE_SPECIALIZATION */
42024202
}
@@ -4471,7 +4471,7 @@ dummy_func(
44714471
_Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, LOCALS_ARRAY);
44724472
DISPATCH_SAME_OPARG();
44734473
}
4474-
STAT_INC(BINARY_OP, deferred);
4474+
OPCODE_DEFERRED_INC(BINARY_OP);
44754475
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
44764476
#endif /* ENABLE_SPECIALIZATION */
44774477
assert(NB_ADD <= oparg);

Python/generated_cases.c.h

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ _Py_GetSpecializationStats(void) {
116116
err += add_stat_dict(stats, STORE_SUBSCR, "store_subscr");
117117
err += add_stat_dict(stats, STORE_ATTR, "store_attr");
118118
err += add_stat_dict(stats, CALL, "call");
119+
err += add_stat_dict(stats, CALL_KW, "call_kw");
119120
err += add_stat_dict(stats, BINARY_OP, "binary_op");
120121
err += add_stat_dict(stats, COMPARE_OP, "compare_op");
121122
err += add_stat_dict(stats, UNPACK_SEQUENCE, "unpack_sequence");

0 commit comments

Comments
 (0)