GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Specialize calls to inherited `list.append` on list subclasses · Issue #155456 · python/cpython Open Labels interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancementProposal:I was reading the code around I am wondering whether inherited For example: class MyList(list): pass def append_one(values): values.append(1) For an exact list, this call can specialize to The specialization is made in It checks that the receiver is an exact list: if ((PyObject *)descr == list_append && oparg == 1) { assert(self_or_null != NULL); if (PyList_CheckExact(self_or_null)) { specialize(instr, CALL_LIST_APPEND); return 0; } } and macro(CALL_LIST_APPEND) = unused/1 + unused/2 + _GUARD_CALLABLE_LIST_APPEND + _GUARD_NOS_NOT_NULL + _GUARD_NOS_LIST + _CALL_LIST_APPEND + POP_TOP + POP_TOP; As far as I understand, this should exclude subclasses that shadow But, The remaining problem is ensuring that the specialization and runtime guards admit them safely. Possible approachThe safer structure seems to be leaving the existing instruction unchanged and adding a separate specialization for list subclasses such as The specializer could select the existing instruction for exact lists and the new instruction for subclasses: if (PyList_CheckExact(self_or_null)) { specialize(instr, CALL_LIST_APPEND); } else if (PyList_Check(self_or_null)) { specialize(instr, CALL_LIST_APPEND_SUBTYPE); } Both instructions could then share macro(CALL_LIST_APPEND) = unused/1 + unused/2 + _GUARD_CALLABLE_LIST_APPEND + _GUARD_NOS_NOT_NULL + _GUARD_NOS_LIST + _CALL_LIST_APPEND + POP_TOP + POP_TOP; macro(CALL_LIST_APPEND_SUBTYPE) = unused/1 + unused/2 + _GUARD_CALLABLE_LIST_APPEND + _GUARD_NOS_NOT_NULL + _GUARD_NOS_LIST_SUBTYPE + _CALL_LIST_APPEND + POP_TOP + POP_TOP; op(_GUARD_NOS_LIST_SUBTYPE, (self -- self)) { EXIT_IF(!PyList_Check(self)); } This keeps the meaning of Alternative approachA smaller alternative would be to let the existing - if (PyList_CheckExact(self_or_null)) { + if (PyList_Check(self_or_null)) { specialize(instr, CALL_LIST_APPEND); } and replace its exact list guard: macro(CALL_LIST_APPEND) =
unused/1 +
unused/2 +
_GUARD_CALLABLE_LIST_APPEND +
_GUARD_NOS_NOT_NULL +
- _GUARD_NOS_LIST +
+ _GUARD_NOS_LIST_SUBTYPE +
_CALL_LIST_APPEND +
POP_TOP +
POP_TOP;It is a smaller code change, but it broadens the meaning of an existing instruction. I have not verified all assumptions outside, so I am not sure that changing the existing instruction is the right approach. Is there any semantic or implementation reason why a list subclass inheriting the built-in If the optimization is worthwhile, would it be preferable to extend the existing instruction, or to keep the new behavior isolated in a separate specialization? Has this already been discussed elsewhere?No response given Links to previous discussion of this feature:Linked PRsActivity
MetadataMetadataAssigneesLabelsinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |