Repository navigation
gh-161467: Enable __attribute__((hot)) for Clang - #161468
Conversation
The history of compiler support for the relevant features is as follows. * GCC introduced `__attribute__((hot))` in GCC 4.3.0. * https://gcc.gnu.org/pipermail/gcc-patches/2017-July/478580.html * GCC has supported for `__has_attribute()` since GCC 5. * https://gcc.gnu.org/gcc-5/changes.html * Clang has supported `__attribute__((hot))` since Clang 3.2. * llvm/llvm-project@29c2b43 * Clang has supported `__has_attribute()` since Clang 2.9. * llvm/llvm-project@274a70e * By default, Clang defines `__GNUC__` as 4, `__GNUC_MINOR__` as 2, and `__GNUC_PATCHLEVEL__` as 1. * llvm/llvm-project#99804 Therefore, `__attribute__((hot))` is not enabled when building CPython with Clang's default configuration. And we can use `_Py__has_attribute(hot)` or `GCC version >= 4.3` to determine whether the hot attribute is supported, and enable this attribute for Clang and other compilers that support it.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Can you please show PyPerformance changes with this, both on a release build and on a PGO build? |
There was a problem hiding this comment.
GCC 5 was releasesd 11 years, IMO it's ok to drop this optimization on GCC 5 which shouldn't be used in the wild anymore. So I suggest to simplify the code (and add indentation for readability):
| #if _Py__has_attribute(hot) | |
| # define _Py_HOT_FUNCTION __attribute__((hot)) | |
| #else | |
| # define _Py_HOT_FUNCTION | |
| #endif |
Note: I'm the one who added _Py_HOT_FUNCTION to Python a few years ago :-)
When using PGO, I'm not sure that
|
|
The comment above says:
We don't know how Clang will behave/optimise, so I think we should be cautious and verify there is no regression before merging. |
- Drop this optimization for GCC versions earlier than GCC5 - Update the issue number in comments
Hi, I conducted the tests on an x86 PC. The results for default builds are shown below. performance-default-baseline.json performance-default-baseline-round2.json Note: For the results in Comparison of Default Builds (Round 1) |
Ah, apt failed with download errors: "Unable to connect to archive.ubuntu.com:http: [IP: 91.189.90.11 80]". Unrelated to this change. |
|
Merged, thanks. |
The history of compiler support for the relevant features is as follows.
__attribute__((hot))in GCC 4.3.0.__has_attribute()since GCC 5.__attribute__((hot))since Clang 3.2.__has_attribute()since Clang 2.9.__GNUC__as 4,__GNUC_MINOR__as 2, and__GNUC_PATCHLEVEL__as 1.__GNUC__macros llvm/llvm-project#99804Therefore,
__attribute__((hot))is not enabled when building CPython with Clang's default configuration. And we can use_Py__has_attribute(hot)orGCC version >= 4.3to determine whether the hot attribute is supported, and enable this attribute for Clang and other compilers that support it.