Skip to content

Duplicated lookup on unicodekeys_lookup_unicode #104717

Closed

Description

@corona10

There are duplicated lookups on unicodekeys_lookup_unicode.
I am trying to understand this code as manual loop unrolling for performance. but I am not sure that it is intended.

ix = dictkeys_get_index(dk, i);
if (ix >= 0) {
PyDictUnicodeEntry *ep = &ep0[ix];
assert(ep->me_key != NULL);
assert(PyUnicode_CheckExact(ep->me_key));
if (ep->me_key == key ||
(unicode_get_hash(ep->me_key) == hash && unicode_eq(ep->me_key, key))) {
return ix;
}
}
else if (ix == DKIX_EMPTY) {
return DKIX_EMPTY;
}
perturb >>= PERTURB_SHIFT;
i = mask & (i*5 + perturb + 1);
ix = dictkeys_get_index(dk, i);
if (ix >= 0) {
PyDictUnicodeEntry *ep = &ep0[ix];
assert(ep->me_key != NULL);
assert(PyUnicode_CheckExact(ep->me_key));
if (ep->me_key == key ||
(unicode_get_hash(ep->me_key) == hash && unicode_eq(ep->me_key, key))) {
return ix;
}
}
else if (ix == DKIX_EMPTY) {
return DKIX_EMPTY;
}
perturb >>= PERTURB_SHIFT;
i = mask & (i*5 + perturb + 1);

First introduced from f8a95df

Please let me know this that is intended.

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    3.11only security fixes
    3.12only security fixes
    on May 21, 2023
  2. corona10 commented on May 21, 2023

    @corona10
    MemberAuthor
  3. added
    type-bugAn unexpected behavior, bug, or error
    and removed
    type-featureA feature request or enhancement
    on May 21, 2023
  4. methane commented on May 21, 2023

    @methane
    Member

    Yes, this is intended, manual loop unrolling.
    This is the hottest path in dictobject.c.
    I don't remember tha actual number of performance gain, but I had confirmed that this had some gain.

  5. removed
    type-bugAn unexpected behavior, bug, or error
    on May 21, 2023
  6. corona10 commented on May 21, 2023

    @corona10
    MemberAuthor

    Okay then I will close the issue.

    Yes, this is intended, manual loop unrolling.

    It will be great if there is a comment about this.

  7. added 2 commits that reference this issue on May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions