Skip to content

Commit 276d777

Browse files
authored
GH-98686: Quicken everything (GH-98687)
1 parent 18fc232 commit 276d777

21 files changed

+144
-239
lines changed

Include/cpython/code.h

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ typedef struct {
7070
PyObject *co_exceptiontable; /* Byte string encoding exception handling \
7171
table */ \
7272
int co_flags; /* CO_..., see below */ \
73-
short co_warmup; /* Warmup counter for quickening */ \
7473
short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \
7574
\
7675
/* The rest are not so impactful on performance. */ \

Include/internal/pycore_code.h

+6-26
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,8 @@ typedef struct {
9191

9292
#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)
9393

94-
#define QUICKENING_WARMUP_DELAY 8
95-
96-
/* We want to compare to zero for efficiency, so we offset values accordingly */
97-
#define QUICKENING_INITIAL_WARMUP_VALUE (-QUICKENING_WARMUP_DELAY)
98-
99-
void _PyCode_Quicken(PyCodeObject *code);
100-
101-
static inline void
102-
_PyCode_Warmup(PyCodeObject *code)
103-
{
104-
if (code->co_warmup != 0) {
105-
code->co_warmup++;
106-
if (code->co_warmup == 0) {
107-
_PyCode_Quicken(code);
108-
}
109-
}
110-
}
111-
11294
extern uint8_t _PyOpcode_Adaptive[256];
11395

114-
extern Py_ssize_t _Py_QuickenedCount;
115-
11696
// Borrowed references to common callables:
11797
struct callable_cache {
11898
PyObject *isinstance;
@@ -252,10 +232,10 @@ extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
252232
int oparg);
253233
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr);
254234

255-
/* Deallocator function for static codeobjects used in deepfreeze.py */
256-
extern void _PyStaticCode_Dealloc(PyCodeObject *co);
257-
/* Function to intern strings of codeobjects */
258-
extern int _PyStaticCode_InternStrings(PyCodeObject *co);
235+
/* Finalizer function for static codeobjects used in deepfreeze.py */
236+
extern void _PyStaticCode_Fini(PyCodeObject *co);
237+
/* Function to intern strings of codeobjects and quicken the bytecode */
238+
extern int _PyStaticCode_Init(PyCodeObject *co);
259239

260240
#ifdef Py_STATS
261241

@@ -397,8 +377,8 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
397377

398378
/* With a 16-bit counter, we have 12 bits for the counter value, and 4 bits for the backoff */
399379
#define ADAPTIVE_BACKOFF_BITS 4
400-
/* The initial counter value is 31 == 2**ADAPTIVE_BACKOFF_START - 1 */
401-
#define ADAPTIVE_BACKOFF_START 5
380+
/* The initial counter value is 1 == 2**ADAPTIVE_BACKOFF_START - 1 */
381+
#define ADAPTIVE_BACKOFF_START 1
402382

403383
#define MAX_BACKOFF_VALUE (16 - ADAPTIVE_BACKOFF_BITS)
404384

Include/internal/pycore_opcode.h

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode.h

+31-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/opcode.py

-6
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ def pseudo_op(name, op, real_ops):
327327
"FOR_ITER_LIST",
328328
"FOR_ITER_RANGE",
329329
],
330-
"JUMP_BACKWARD": [
331-
"JUMP_BACKWARD_QUICK",
332-
],
333330
"LOAD_ATTR": [
334331
"LOAD_ATTR_ADAPTIVE",
335332
# These potentially push [NULL, bound method] onto the stack.
@@ -358,9 +355,6 @@ def pseudo_op(name, op, real_ops):
358355
"LOAD_GLOBAL_BUILTIN",
359356
"LOAD_GLOBAL_MODULE",
360357
],
361-
"RESUME": [
362-
"RESUME_QUICK",
363-
],
364358
"STORE_ATTR": [
365359
"STORE_ATTR_ADAPTIVE",
366360
"STORE_ATTR_INSTANCE_VALUE",

Lib/test/libregrtest/refleak.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def get_pooled_int(value):
7373
fd_deltas = [0] * repcount
7474
getallocatedblocks = sys.getallocatedblocks
7575
gettotalrefcount = sys.gettotalrefcount
76-
_getquickenedcount = sys._getquickenedcount
7776
fd_count = os_helper.fd_count
7877
# initialize variables to make pyflakes quiet
7978
rc_before = alloc_before = fd_before = 0
@@ -93,7 +92,7 @@ def get_pooled_int(value):
9392
support.gc_collect()
9493

9594
# Read memory statistics immediately after the garbage collection
96-
alloc_after = getallocatedblocks() - _getquickenedcount()
95+
alloc_after = getallocatedblocks()
9796
rc_after = gettotalrefcount()
9897
fd_after = fd_count()
9998

Lib/test/test_call.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def testfunction_kw(self, *, kw):
580580
return self
581581

582582

583-
QUICKENING_WARMUP_DELAY = 8
583+
ADAPTIVE_WARMUP_DELAY = 2
584584

585585

586586
class TestPEP590(unittest.TestCase):
@@ -771,7 +771,7 @@ def f(num): return num + 1
771771
assert_equal(11, f(num))
772772
function_setvectorcall(f)
773773
# make sure specializer is triggered by running > 50 times
774-
for _ in range(10 * QUICKENING_WARMUP_DELAY):
774+
for _ in range(10 * ADAPTIVE_WARMUP_DELAY):
775775
assert_equal("overridden", f(num))
776776

777777
def test_setvectorcall_load_attr_specialization_skip(self):
@@ -787,7 +787,7 @@ def __getattribute__(self, attr):
787787
function_setvectorcall(X.__getattribute__)
788788
# make sure specialization doesn't trigger
789789
# when vectorcall is overridden
790-
for _ in range(QUICKENING_WARMUP_DELAY):
790+
for _ in range(ADAPTIVE_WARMUP_DELAY):
791791
assert_equal("overridden", x.a)
792792

793793
def test_setvectorcall_load_attr_specialization_deopt(self):
@@ -803,12 +803,12 @@ def get_a(x):
803803
assert_equal = self.assertEqual
804804
x = X()
805805
# trigger LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN specialization
806-
for _ in range(QUICKENING_WARMUP_DELAY):
806+
for _ in range(ADAPTIVE_WARMUP_DELAY):
807807
assert_equal("a", get_a(x))
808808
function_setvectorcall(X.__getattribute__)
809809
# make sure specialized LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
810810
# gets deopted due to overridden vectorcall
811-
for _ in range(QUICKENING_WARMUP_DELAY):
811+
for _ in range(ADAPTIVE_WARMUP_DELAY):
812812
assert_equal("overridden", get_a(x))
813813

814814
@requires_limited_api

0 commit comments

Comments
 (0)