Skip to content

Let clang on Linux and clang-cl on Windows "see" more optimizing macros #131033

Description

@chris-eibl

Feature or enhancement

Proposal:

Here are a few optimizing macros, some of which clang under Linux does not "see", because

None of these are seen by clang-cl on Windows, because there

  • clang-cl does not set __GNUC__ (most probably because too much code out there would then assume "ah - I am on Linux")
  • but clang-cl does set __clang__

IMHO, "syncing" them between GCC/clang on Linux and clang-cl on Windows is preferable.

Neither seen on Linux nor on Windows: #130891 would fix:

cpython/Include/pyport.h

Lines 323 to 325 in 98fa4a4

#if defined(__GNUC__) \
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
#define_Py_HOT_FUNCTION__attribute__((hot))

Seen on Linux, not seen on Windows: #131019 would fix:

cpython/Objects/obmalloc.c

Lines 1460 to 1462 in 98fa4a4

#if defined(__GNUC__) && (__GNUC__>2) && defined(__OPTIMIZE__)
# defineUNLIKELY(value) __builtin_expect((value), 0)
# defineLIKELY(value) __builtin_expect((value), 1)

Seen on Linux, not seen on Windows:

#if defined(__GNUC__) \
&& (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
# defineXML_ATTR_MALLOC__attribute__((__malloc__))

Neither seen on Linux nor on Windows:

#if defined(__GNUC__) \
&& ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
# defineXML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))

The last two are in vendored code, but I've temporarily modified it (01183d7) and then reverted again (1c4a55d)

Enabling them all for clang-cl on Windows is performance neutral wrt to the pyperformance benchmark.

Benchmarkclang.release.19.1.1.92e5f826acclang.release.19.1.1.16a7f4607e.pyHot
Geometric mean(ref)1.01x faster
Benchmarkclang.pgo.19.1.1.92e5f826acclang.pgo.19.1.1.16a7f4607e.pyHot
Geometric mean(ref)1.01x slower
Benchmarkclang.release.20.1.0-rc2.92e5f826acclang.release.20.1.0-rc2.16a7f4607e.pyHot
Geometric mean(ref)1.01x faster
Benchmarkclang.pgo.20.1.0-rc2.92e5f826acclang.pgo.20.1.0-rc2.16a7f4607e.pyHot
Geometric mean(ref)1.00x slower
Details

Benchmarkclang.release.19.1.1.92e5f826acclang.release.19.1.1.16a7f4607e.pyHot
telco11.9 ms10.9 ms: 1.10x faster
xml_etree_parse236 ms217 ms: 1.09x faster
logging_format15.8 us15.0 us: 1.05x faster
async_tree_eager145 ms138 ms: 1.05x faster
async_tree_none_tg375 ms358 ms: 1.05x faster
unpickle_list5.83 us5.57 us: 1.05x faster
xml_etree_iterparse157 ms150 ms: 1.05x faster
unpickle23.0 us22.0 us: 1.05x faster
async_tree_memoization_tg460 ms442 ms: 1.04x faster
xml_etree_generate142 ms137 ms: 1.04x faster
nqueens125 ms120 ms: 1.04x faster
async_tree_memoization490 ms472 ms: 1.04x faster
async_tree_io876 ms844 ms: 1.04x faster
logging_simple14.3 us13.8 us: 1.04x faster
deepcopy_reduce3.92 us3.78 us: 1.04x faster
crypto_pyaes104 ms101 ms: 1.04x faster
pprint_pformat2.18 sec2.10 sec: 1.04x faster
async_tree_none391 ms378 ms: 1.03x faster
pprint_safe_repr1.06 sec1.02 sec: 1.03x faster
async_tree_eager_memoization290 ms281 ms: 1.03x faster
json_dumps16.5 ms16.0 ms: 1.03x faster
fannkuch580 ms562 ms: 1.03x faster
scimark_sparse_mat_mult5.76 ms5.59 ms: 1.03x faster
async_tree_eager_io822 ms798 ms: 1.03x faster
xml_etree_process96.4 ms93.7 ms: 1.03x faster
async_tree_eager_tg307 ms299 ms: 1.03x faster
scimark_fft481 ms470 ms: 1.03x faster
coroutines31.9 ms31.2 ms: 1.02x faster
async_tree_io_tg853 ms834 ms: 1.02x faster
pathlib255 ms250 ms: 1.02x faster
typing_runtime_protocols224 us220 us: 1.02x faster
django_template53.7 ms52.8 ms: 1.02x faster
sympy_expand650 ms640 ms: 1.02x faster
unpickle_pure_python305 us300 us: 1.02x faster
async_tree_eager_memoization_tg411 ms405 ms: 1.02x faster
async_tree_cpu_io_mixed_tg752 ms741 ms: 1.02x faster
chaos88.2 ms86.9 ms: 1.02x faster
sqlite_synth3.57 us3.52 us: 1.01x faster
tomli_loads2.70 sec2.66 sec: 1.01x faster
pickle_pure_python444 us438 us: 1.01x faster
sqlglot_normalize150 ms148 ms: 1.01x faster
regex_compile171 ms169 ms: 1.01x faster
mako17.3 ms17.1 ms: 1.01x faster
sqlglot_parse1.67 ms1.65 ms: 1.01x faster
sympy_sum211 ms208 ms: 1.01x faster
hexiom8.26 ms8.19 ms: 1.01x faster
sqlglot_transpile2.06 ms2.04 ms: 1.01x faster
sqlglot_optimize74.0 ms73.4 ms: 1.01x faster
python_startup43.2 ms42.9 ms: 1.01x faster
async_generators540 ms536 ms: 1.01x faster
gc_traversal4.82 ms4.79 ms: 1.01x faster
comprehensions23.2 us23.1 us: 1.01x faster
generators38.1 ms37.8 ms: 1.01x faster
richards_super73.9 ms73.4 ms: 1.01x faster
deepcopy376 us373 us: 1.01x faster
genshi_text29.8 ms29.6 ms: 1.01x faster
pickle_dict32.3 us32.2 us: 1.00x faster
scimark_sor168 ms169 ms: 1.01x slower
go145 ms146 ms: 1.01x slower
pyflate596 ms602 ms: 1.01x slower
logging_silent133 ns135 ns: 1.01x slower
dulwich_log130 ms132 ms: 1.01x slower
regex_v835.2 ms35.6 ms: 1.01x slower
spectral_norm128 ms130 ms: 1.02x slower
docutils3.60 sec3.66 sec: 1.02x slower
sympy_integrate26.4 ms26.8 ms: 1.02x slower
scimark_monte_carlo90.7 ms92.6 ms: 1.02x slower
float102 ms105 ms: 1.02x slower
2to3429 ms439 ms: 1.02x slower
nbody151 ms155 ms: 1.03x slower
genshi_xml71.7 ms74.2 ms: 1.04x slower
Geometric mean(ref)1.01x faster
Benchmarkclang.pgo.19.1.1.92e5f826acclang.pgo.19.1.1.16a7f4607e.pyHot
2to3465 ms380 ms: 1.22x faster
async_generators506 ms490 ms: 1.03x faster
coroutines27.1 ms26.4 ms: 1.03x faster
pidigits233 ms228 ms: 1.02x faster
pickle_dict27.8 us27.3 us: 1.02x faster
sympy_sum187 ms184 ms: 1.02x faster
typing_runtime_protocols186 us183 us: 1.02x faster
raytrace309 ms305 ms: 1.02x faster
unpickle16.6 us16.4 us: 1.01x faster
genshi_xml60.4 ms59.5 ms: 1.01x faster
regex_compile151 ms149 ms: 1.01x faster
scimark_sparse_mat_mult4.82 ms4.77 ms: 1.01x faster
unpack_sequence55.7 ns55.1 ns: 1.01x faster
sqlglot_parse1.42 ms1.41 ms: 1.01x faster
sqlglot_transpile1.75 ms1.73 ms: 1.01x faster
telco9.01 ms8.91 ms: 1.01x faster
logging_format12.9 us12.8 us: 1.01x faster
unpickle_list5.04 us4.99 us: 1.01x faster
nqueens95.3 ms94.4 ms: 1.01x faster
async_tree_eager_io720 ms714 ms: 1.01x faster
sympy_expand556 ms551 ms: 1.01x faster
scimark_lu124 ms123 ms: 1.01x faster
docutils3.09 sec3.07 sec: 1.01x faster
chaos69.1 ms68.7 ms: 1.01x faster
sqlglot_optimize63.5 ms63.1 ms: 1.01x faster
sympy_integrate22.9 ms22.7 ms: 1.01x faster
spectral_norm106 ms105 ms: 1.00x faster
scimark_fft352 ms351 ms: 1.00x faster
deepcopy298 us300 us: 1.00x slower
generators34.0 ms34.2 ms: 1.01x slower
meteor_contest119 ms119 ms: 1.01x slower
logging_silent106 ns106 ns: 1.01x slower
tomli_loads2.21 sec2.22 sec: 1.01x slower
pickle_pure_python367 us369 us: 1.01x slower
regex_effbot3.21 ms3.24 ms: 1.01x slower
pyflate514 ms518 ms: 1.01x slower
sqlite_synth3.41 us3.44 us: 1.01x slower
deltablue3.66 ms3.69 ms: 1.01x slower
unpickle_pure_python247 us249 us: 1.01x slower
nbody126 ms128 ms: 1.01x slower
scimark_sor140 ms141 ms: 1.01x slower
mdp3.13 sec3.16 sec: 1.01x slower
pprint_safe_repr891 ms899 ms: 1.01x slower
go126 ms127 ms: 1.01x slower
richards_super52.0 ms52.6 ms: 1.01x slower
async_tree_eager116 ms117 ms: 1.01x slower
regex_dna204 ms207 ms: 1.01x slower
create_gc_cycles1.49 ms1.51 ms: 1.01x slower
richards45.4 ms46.0 ms: 1.01x slower
deepcopy_memo33.4 us34.1 us: 1.02x slower
async_tree_eager_tg267 ms273 ms: 1.02x slower
json_loads31.2 us31.9 us: 1.02x slower
pprint_pformat1.79 sec1.85 sec: 1.03x slower
gc_traversal5.03 ms5.28 ms: 1.05x slower
xml_etree_parse208 ms220 ms: 1.06x slower
async_tree_io759 ms832 ms: 1.10x slower
asyncio_tcp1.38 sec1.52 sec: 1.10x slower
xml_etree_process78.5 ms87.4 ms: 1.11x slower
xml_etree_generate114 ms128 ms: 1.11x slower
async_tree_memoization_tg392 ms449 ms: 1.15x slower
async_tree_io_tg746 ms855 ms: 1.15x slower
async_tree_memoization414 ms477 ms: 1.15x slower
async_tree_none_tg325 ms382 ms: 1.17x slower
xml_etree_iterparse141 ms172 ms: 1.22x slower
Geometric mean(ref)1.01x slower
Benchmarkclang.release.20.1.0-rc2.92e5f826acclang.release.20.1.0-rc2.16a7f4607e.pyHot
spectral_norm139 ms124 ms: 1.13x faster
pickle_list5.89 us5.46 us: 1.08x faster
sqlite_synth3.71 us3.51 us: 1.06x faster
pickle_dict32.3 us30.7 us: 1.05x faster
unpickle20.8 us20.0 us: 1.04x faster
json_loads43.0 us41.3 us: 1.04x faster
unpickle_list5.35 us5.15 us: 1.04x faster
mako16.9 ms16.3 ms: 1.04x faster
pprint_safe_repr1.01 sec976 ms: 1.03x faster
crypto_pyaes102 ms98.7 ms: 1.03x faster
coverage111 ms108 ms: 1.03x faster
coroutines30.3 ms29.5 ms: 1.03x faster
telco10.4 ms10.2 ms: 1.03x faster
json_dumps15.6 ms15.3 ms: 1.02x faster
asyncio_websockets547 ms534 ms: 1.02x faster
scimark_sparse_mat_mult5.94 ms5.81 ms: 1.02x faster
pprint_pformat2.07 sec2.02 sec: 1.02x faster
unpickle_pure_python300 us294 us: 1.02x faster
xml_etree_parse218 ms214 ms: 1.02x faster
xml_etree_generate135 ms133 ms: 1.02x faster
async_generators510 ms501 ms: 1.02x faster
typing_runtime_protocols217 us213 us: 1.02x faster
mdp3.72 sec3.67 sec: 1.02x faster
scimark_fft437 ms431 ms: 1.01x faster
bench_thread_pool1.79 ms1.77 ms: 1.01x faster
deepcopy_reduce3.71 us3.66 us: 1.01x faster
docutils3.56 sec3.52 sec: 1.01x faster
async_tree_memoization_tg433 ms428 ms: 1.01x faster
sqlglot_transpile2.02 ms2.00 ms: 1.01x faster
genshi_xml69.7 ms69.0 ms: 1.01x faster
xml_etree_process92.2 ms91.3 ms: 1.01x faster
fannkuch539 ms535 ms: 1.01x faster
sqlglot_normalize144 ms143 ms: 1.01x faster
float102 ms101 ms: 1.01x faster
raytrace361 ms358 ms: 1.01x faster
sqlglot_parse1.64 ms1.63 ms: 1.01x faster
gc_traversal4.84 ms4.80 ms: 1.01x faster
nqueens117 ms116 ms: 1.01x faster
meteor_contest123 ms123 ms: 1.01x faster
sqlglot_optimize71.4 ms71.1 ms: 1.00x faster
comprehensions23.0 us22.9 us: 1.00x faster
pidigits240 ms240 ms: 1.00x faster
unpack_sequence55.0 ns55.2 ns: 1.00x slower
chaos84.3 ms84.7 ms: 1.00x slower
dulwich_log126 ms126 ms: 1.00x slower
regex_compile165 ms166 ms: 1.00x slower
hexiom8.01 ms8.07 ms: 1.01x slower
async_tree_cpu_io_mixed_tg708 ms714 ms: 1.01x slower
async_tree_eager134 ms135 ms: 1.01x slower
richards_super73.2 ms73.9 ms: 1.01x slower
deltablue4.31 ms4.35 ms: 1.01x slower
asyncio_tcp_ssl3.59 sec3.64 sec: 1.01x slower
2to3418 ms423 ms: 1.01x slower
scimark_sor159 ms162 ms: 1.02x slower
python_startup40.9 ms41.7 ms: 1.02x slower
scimark_lu143 ms146 ms: 1.02x slower
async_tree_eager_cpu_io_mixed551 ms565 ms: 1.03x slower
go146 ms150 ms: 1.03x slower
generators38.2 ms39.7 ms: 1.04x slower
nbody136 ms142 ms: 1.05x slower
Geometric mean(ref)1.01x faster
Benchmarkclang.pgo.20.1.0-rc2.92e5f826acclang.pgo.20.1.0-rc2.16a7f4607e.pyHot
pickle_pure_python383 us364 us: 1.05x faster
pprint_safe_repr863 ms840 ms: 1.03x faster
regex_effbot3.20 ms3.13 ms: 1.02x faster
pickle_list4.77 us4.66 us: 1.02x faster
typing_runtime_protocols178 us174 us: 1.02x faster
pprint_pformat1.78 sec1.74 sec: 1.02x faster
xml_etree_generate110 ms108 ms: 1.02x faster
richards45.1 ms44.3 ms: 1.02x faster
scimark_sor138 ms136 ms: 1.01x faster
gc_traversal5.21 ms5.15 ms: 1.01x faster
xml_etree_process76.3 ms75.5 ms: 1.01x faster
async_tree_eager113 ms111 ms: 1.01x faster
xml_etree_parse202 ms201 ms: 1.01x faster
nqueens92.3 ms91.4 ms: 1.01x faster
coroutines24.9 ms24.7 ms: 1.01x faster
mako13.4 ms13.3 ms: 1.01x faster
meteor_contest118 ms118 ms: 1.00x faster
unpickle_pure_python247 us246 us: 1.00x faster
sqlglot_normalize120 ms119 ms: 1.00x faster
deltablue3.69 ms3.71 ms: 1.00x slower
sympy_integrate22.6 ms22.7 ms: 1.00x slower
deepcopy289 us291 us: 1.01x slower
sympy_sum181 ms182 ms: 1.01x slower
unpack_sequence55.1 ns55.4 ns: 1.01x slower
2to3370 ms373 ms: 1.01x slower
asyncio_tcp_ssl3.52 sec3.55 sec: 1.01x slower
sqlite_synth3.20 us3.22 us: 1.01x slower
async_tree_eager_io701 ms707 ms: 1.01x slower
sqlglot_parse1.38 ms1.40 ms: 1.01x slower
pidigits228 ms230 ms: 1.01x slower
async_tree_io_tg727 ms735 ms: 1.01x slower
dulwich_log115 ms117 ms: 1.01x slower
python_startup39.4 ms39.9 ms: 1.01x slower
chaos67.0 ms67.9 ms: 1.01x slower
raytrace299 ms303 ms: 1.01x slower
nbody119 ms120 ms: 1.01x slower
async_tree_eager_tg260 ms264 ms: 1.01x slower
scimark_lu122 ms124 ms: 1.02x slower
python_startup_no_site34.0 ms34.5 ms: 1.02x slower
regex_dna204 ms208 ms: 1.02x slower
crypto_pyaes81.1 ms82.7 ms: 1.02x slower
scimark_fft341 ms349 ms: 1.02x slower
scimark_sparse_mat_mult4.53 ms4.65 ms: 1.03x slower
sympy_str320 ms329 ms: 1.03x slower
bench_thread_pool1.63 ms1.68 ms: 1.03x slower
deepcopy_reduce2.96 us3.06 us: 1.03x slower
tomli_loads2.20 sec2.28 sec: 1.03x slower
pathlib232 ms241 ms: 1.04x slower
telco8.45 ms8.77 ms: 1.04x slower
unpickle15.6 us16.2 us: 1.04x slower
pickle13.5 us14.3 us: 1.05x slower
async_tree_memoization405 ms428 ms: 1.06x slower
async_tree_io740 ms784 ms: 1.06x slower
Geometric mean(ref)1.00x slower

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildperformancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions