Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-124153: Fix unstable optimization of PyType_GetBaseByToken() and friends #124488

Merged
merged 14 commits into from
Oct 10, 2024

Conversation

neonene
Copy link
Contributor

@neonene neonene commented Sep 25, 2024

An alternative PR to #124323.

This helps MSVC to optimize PyType_GetBaseByToken() and PyType_GetModuleByDef() on PGO builds without current workaround.

cc @encukou

Objects/typeobject.c Outdated Show resolved Hide resolved
@neonene neonene marked this pull request as draft September 25, 2024 21:10
@neonene
Copy link
Contributor Author

neonene commented Oct 2, 2024

One of suspects that exhausts MSVC:

 static PyTypeObject *
-get_base_by_token_recursive(PyTypeObject *type, void *token)
+get_base_by_token_recursive(PyObject *bases, void *token)

@neonene neonene marked this pull request as ready for review October 8, 2024 15:09
@neonene
Copy link
Contributor Author

neonene commented Oct 8, 2024

@encukou Please review again. This should not be bad for performance on average.

@neonene
Copy link
Contributor Author

neonene commented Oct 9, 2024

Bad example:

    PyTypeObject *base = NULL;
    if (((PyHeapTypeObject*)type)->ht_token == token) {
found:
        if (result != NULL) {
            *result = (PyTypeObject *)Py_NewRef(base ? base : type);
        }
        return 1;
    }

Are you interested in removing the checker function like the current PR? If not, I'll give up.

not to impact PyType_GetSlot() and others.
Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Thank you, and apologies for the delay.

@encukou encukou merged commit 120b891 into python:main Oct 10, 2024
38 checks passed
@neonene neonene deleted the opttoken branch October 10, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants