Dennis Sweeney <sweeney.dennis...@gmail.com> added the comment:
I made the requested changes to reflect that this is for code cleanliness rather than strictly for performance. However, it appears that Visual Studio on Windows 10 was not doing the optimization one might expect. In particular, here is the disassembly before this PR: =========================================== PyObject *vitem = vl->ob_item[i]; 78E20C49 mov eax,dword ptr [edx+0Ch] PyObject *vitem = vl->ob_item[i]; 78E20C4C mov ecx,dword ptr [eax+edi*4] PyObject *witem = wl->ob_item[i]; 78E20C4F mov eax,dword ptr [esi+0Ch] 78E20C52 mov dword ptr [vitem],ecx 78E20C55 mov esi,dword ptr [eax+edi*4] 78E20C58 mov dword ptr [witem],esi if (vitem == witem) { 78E20C5B cmp ecx,esi 78E20C5D je list_richcompare+12Bh (78E20CFBh) continue; } Py_INCREF(vitem); 78E20C63 inc dword ptr [ecx] Py_INCREF(witem); 78E20C65 inc dword ptr [esi] int k = PyObject_RichCompareBool(vl->ob_item[i], 78E20C67 mov eax,dword ptr [w] 78E20C6A mov eax,dword ptr [eax+0Ch] 78E20C6D mov ebx,dword ptr [eax+edi*4] 78E20C70 mov eax,dword ptr [edx+0Ch] 78E20C73 mov eax,dword ptr [eax+edi*4] 78E20C76 cmp eax,ebx 78E20C78 jne list_richcompare+0B1h (78E20C81h) 78E20C7A mov ebx,1 78E20C7F jmp list_richcompare+100h (78E20CD0h) 78E20C81 push 2 78E20C83 push ebx 78E20C84 push eax 78E20C85 call PyObject_RichCompare (78E35120h) 78E20C8A mov esi,eax 78E20C8C add esp,0Ch 78E20C8F test esi,esi 78E20C91 jne list_richcompare+0C8h (78E20C98h) 78E20C93 or ebx,0FFFFFFFFh 78E20C96 jmp list_richcompare+0FAh (78E20CCAh) 78E20C98 cmp dword ptr [esi+4],offset PyBool_Type (790A3420h) =========================================== And after this PR: =========================================== PyObject *vitem = vl->ob_item[i]; 795E0C4A mov eax,dword ptr [edx+0Ch] PyObject *vitem = vl->ob_item[i]; 795E0C4D mov ebx,dword ptr [eax+ecx*4] PyObject *witem = wl->ob_item[i]; 795E0C50 mov eax,dword ptr [edi+0Ch] 795E0C53 mov edi,dword ptr [eax+ecx*4] if (vitem == witem) { 795E0C56 cmp ebx,edi 795E0C58 je list_richcompare+109h (795E0CD9h) continue; } Py_INCREF(vitem); 795E0C5A inc dword ptr [ebx] Py_INCREF(witem); 795E0C5C inc dword ptr [edi] int k = PyObject_RichCompareBool(vitem, witem, Py_EQ); 795E0C5E push 2 795E0C60 push edi 795E0C61 push ebx 795E0C62 call PyObject_RichCompare (795F5120h) 795E0C67 mov esi,eax 795E0C69 add esp,0Ch 795E0C6C test esi,esi 795E0C6E jne list_richcompare+0A5h (795E0C75h) 795E0C70 or esi,0FFFFFFFFh 795E0C73 jmp list_richcompare+0DBh (795E0CABh) 795E0C75 cmp dword ptr [esi+4],offset PyBool_Type (79863420h) 795E0C7C jne list_richcompare+0BBh (795E0C8Bh) 795E0C7E xor eax,eax 795E0C80 cmp esi,offset _Py_TrueStruct (798633FCh) 795E0C86 sete al 795E0C89 jmp list_richcompare+0C4h (795E0C94h) 795E0C8B push esi 795E0C8C call PyObject_IsTrue (795F62F0h) 795E0C91 add esp,4 795E0C94 add dword ptr [esi],0FFFFFFFFh 795E0C97 mov dword ptr [k],eax 795E0C9A jne list_richcompare+0D8h (795E0CA8h) =========================================== ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39737> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com