This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger, serhiy.storchaka
Date 2016-01-25.19:25:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453749940.01.0.185085396815.issue26201@psf.upfronthosting.co.za>
In-reply-to
Content
A number of fine-grained methods in Objects/listobject.c use PyList_Check().  They include PyList_Size, PyList_GetItem, PyList_SetItem, PyList_Insert, and PyList_Append.

The PyList_Check() works by making two sequentially dependent memory fetches:

    movq    8(%rdi), %rax
    testb   $2, 171(%rax)
    je  L1645

This patch proposes a fast path for the common case of an exact match, using PyList_CheckExact() as an early-out before the PyList_Check() test:

    leaq    _PyList_Type(%rip), %rdx # parallelizable
    movq    8(%rdi), %rax            # only 1 memory access
    cmpq    %rdx, %rax               # macro-fusion  
    je  L1604                        # early-out
    testb   $2, 171(%rax)            # fallback to 2nd memory access
    je  L1604

This technique won't help outside of Objects/listobject.c because the initial LEA instruction becomes a MOV for the global offset table, nullifying the advantage.
History
Date User Action Args
2016-01-25 19:25:40rhettingersetrecipients: + rhettinger, serhiy.storchaka
2016-01-25 19:25:40rhettingersetmessageid: <1453749940.01.0.185085396815.issue26201@psf.upfronthosting.co.za>
2016-01-25 19:25:39rhettingerlinkissue26201 messages
2016-01-25 19:25:39rhettingercreate