Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4345253

Browse files
authored
gh-134584: Eliminate redundant refcounting from_STORE_ATTR_WITH_HINT (GH-142767)
Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent8c87bcd commit4345253

File tree

10 files changed

+69
-17
lines changed

10 files changed

+69
-17
lines changed

‎Include/internal/pycore_opcode_metadata.h‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Include/internal/pycore_uop_ids.h‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Include/internal/pycore_uop_metadata.h‎

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

‎Lib/test/test_capi/test_opt.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,26 @@ class C:
26122612
self.assertNotIn("_POP_TOP",uops)
26132613
self.assertIn("_POP_TOP_NOP",uops)
26142614

2615+
deftest_store_attr_with_hint(self):
2616+
deftestfunc(n):
2617+
classC:
2618+
pass
2619+
c=C()
2620+
foriinrange(_testinternalcapi.SHARED_KEYS_MAX_SIZE-1):
2621+
setattr(c,f"_{i}",None)
2622+
2623+
foriinrange(n):
2624+
c.x=i
2625+
returnc.x
2626+
res,ex=self._run_with_optimizer(testfunc,TIER2_THRESHOLD)
2627+
self.assertEqual(res,TIER2_THRESHOLD-1)
2628+
self.assertIsNotNone(ex)
2629+
uops=get_opnames(ex)
2630+
2631+
self.assertIn("_STORE_ATTR_WITH_HINT",uops)
2632+
self.assertNotIn("_POP_TOP",uops)
2633+
self.assertIn("_POP_TOP_NOP",uops)
2634+
26152635
deftest_store_subscr_int(self):
26162636
deftestfunc(n):
26172637
l= [0,0,0,0]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Eliminate redundant refcounting from ``_STORE_ATTR_WITH_HINT``.

‎Python/bytecodes.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ dummy_func(
26032603
_STORE_ATTR_INSTANCE_VALUE+
26042604
POP_TOP;
26052605

2606-
op(_STORE_ATTR_WITH_HINT, (hint/1,value,owner--)) {
2606+
op(_STORE_ATTR_WITH_HINT, (hint/1,value,owner--o)) {
26072607
PyObject*owner_o=PyStackRef_AsPyObjectBorrow(owner);
26082608
assert(Py_TYPE(owner_o)->tp_flags&Py_TPFLAGS_MANAGED_DICT);
26092609
PyDictObject*dict=_PyObject_GetManagedDict(owner_o);
@@ -2633,14 +2633,16 @@ dummy_func(
26332633
// old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault,
26342634
// when dict only holds the strong reference to value in ep->me_value.
26352635
STAT_INC(STORE_ATTR,hit);
2636-
PyStackRef_CLOSE(owner);
2636+
o=owner;
2637+
DEAD(owner);
26372638
Py_XDECREF(old_value);
26382639
}
26392640

26402641
macro(STORE_ATTR_WITH_HINT)=
26412642
unused/1+
26422643
_GUARD_TYPE_VERSION+
2643-
_STORE_ATTR_WITH_HINT;
2644+
_STORE_ATTR_WITH_HINT+
2645+
POP_TOP;
26442646

26452647
op(_STORE_ATTR_SLOT, (index/1,value,owner--o)) {
26462648
PyObject*owner_o=PyStackRef_AsPyObjectBorrow(owner);

‎Python/executor_cases.c.h‎

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Python/generated_cases.c.h‎

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Python/optimizer_bytecodes.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ dummy_func(void) {
104104
o=owner;
105105
}
106106

107+
op(_STORE_ATTR_WITH_HINT, (hint/1,value,owner--o)) {
108+
(void)value;
109+
o=owner;
110+
}
111+
107112
op(_STORE_FAST, (value--)) {
108113
GETLOCAL(oparg)=value;
109114
}

‎Python/optimizer_cases.c.h‎

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp