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 methane
Recipients methane, rhettinger, xiang.zhang
Date 2017-01-18.05:42:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484718142.72.0.36341437894.issue29304@psf.upfronthosting.co.za>
In-reply-to
Content
Raymond, I understand your worries.  I won't commit this until I do more precise survey.

But why I trying this is not only I find duplicated code.
I think benefit of this technique is reduced by historical reason.


In Python 2.7, there are only two lookup functions: lookdict and lookdict_string.
Both functions support dict containing dummy entry.

In the first comparing part in the lookdict_string():

    if (ep->me_key == NULL || ep->me_key == key)
        return ep;
    if (ep->me_key == dummy)
        freeslot = ep;
    else {
        if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key))
            return ep;
        freeslot = NULL;
    }

And similar code in same function but in loop:

        if (ep->me_key == NULL)
            return freeslot == NULL ? ep : freeslot;
        if (ep->me_key == key
            || (ep->me_hash == hash
            && ep->me_key != dummy
            && _PyString_Eq(ep->me_key, key)))
            return ep;
        if (ep->me_key == dummy && freeslot == NULL)
            freeslot = ep;

First part can ignore freeslot variable is NULL or not.  But second lookup can't.
Since most lookup is done at first try, this technique may had significant effect.


But for now, we're having five lookdict functions (if we include lookdict_index).

Three of them (lookdict_unicode_nodummy, lookdict_split, and lookdict_index) cares only dict without dummies.
They don't have freeslot variable.  So first part and second part is almost same.
Performance benefit from this technique may be negligible.

About remaining two functions (lookdict_unicode and lookdict), this technique may have still effect.
But performance of them are not so important now, compared with Python 2.7.
They were used for all name lookup in Python 2.7, but they are fallback of lookdict_split and lookdict_unicode_nodummy now.

On the other hand, having 2.5x (2 -> 5) lookdict function means maintenance cost of duplicated code is increased.


At first, I'll start three functions which doesn't take care of dummies.
I think there are almost zero performance regression.
History
Date User Action Args
2017-01-18 05:42:22methanesetrecipients: + methane, rhettinger, xiang.zhang
2017-01-18 05:42:22methanesetmessageid: <1484718142.72.0.36341437894.issue29304@psf.upfronthosting.co.za>
2017-01-18 05:42:22methanelinkissue29304 messages
2017-01-18 05:42:21methanecreate