Repository navigation
Conversation
Decode short UTF-8 strings directly and use code point counts and character widths to size longer results.
|
🤖 New build scheduled with the buildbot fleet by @methane for commit f38f5a5 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F163145%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
I'm worried the 0.67x case is not rare. The new code tries the fast grouped path on every 2- and 3-byte character, and when the neighbours are a different width that attempt fails and is wasted work, which seems like something that happens all the time in real text (e.g. Vietnamese, Latin text with accents, short Cyrillic or Greek words). The benchmarks mostly show long runs of same-width characters, and they were built with |
Closes #163144.
Decode short non-ASCII inputs into a stack buffer so the result can be allocated at its final width. Return single characters directly. For longer inputs, skip the known ASCII prefix when counting code points and decode runs of two- or three-byte UTF-8 characters in groups.
Measured
bytes.decode()speedup relative to the PR base (f31608088bb). Values are the median of 12 paired runs on one x86-64 core with GCC 14.2,-O3 -fno-tree-vectorize, and PGO and LTO disabled.日a🙂éΩb(16,384 characters)The alternating-width input takes about 50% longer in both builds.
Strict UTF-8 decoding raises
UnicodeDecodeErrordirectly even when an application has registered a replacement handler namedstrict. For mutable inputs, the sizing pass assumes the buffer stays unchanged until decoding finishes.