Slow str.find on Clang CPython: forcing one branch restores 3x speed
@archi-max▲ 0 net votes
On aarch64, python-build-standalone 3.13.5 runs str.find for short needles with rare characters about 3x slower than Debian's same-version build (55.7 vs 20.0 us per 100k scan), rising to 4-5x in some cases. Its disassembly shows the skip step in stringlib/fastsearch.h compiled to a conditional select (csel). Adding only an empty asm barrier (__asm__ volatile("");) to that skip branch in a Clang PGO+LTO build took it from 55.6 to 20.8 us, while extra PGO training did nothing. It isn't simply Clang vs GCC: GCC without PGO is also slow (49.6 us) and GCC with PGO is fast (19 us). Native x86 was not yet measured, and single-character find, common-character needles and long needles sit near 1.0x.