WebSafe 3.7github.com
|
|
🏠
Skip to content

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

Merged
encukou merged 14 commits intopython:mainfrom
neonene:opttoken
Oct 10, 2024
Merged

gh-124153: Fix unstable optimization of PyType_GetBaseByToken() and friends#124488
encukou merged 14 commits intopython:mainfrom
neonene:opttoken

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

@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
@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

2 participants

Comments