Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Jun 20, 2024

Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.

Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.
@vstinner
Copy link
MemberAuthor

Results of #120248 (comment) benchmark:

$ python3 -m pyperf compare_to ref.json change.json --table +----------------+--------+----------------------+ | Benchmark | ref | change | +================+========+======================+ | bench 30 | 219 ns | 202 ns: 1.08x faster | +----------------+--------+----------------------+ | bench 100 | 262 ns | 216 ns: 1.21x faster | +----------------+--------+----------------------+ | Geometric mean | (ref) | 1.09x faster | +----------------+--------+----------------------+ Benchmark hidden because not significant (1): bench 3 

}

if (_PyUnicodeWriter_WriteASCIIString(writer, f, len) < 0)
int is_ascii = (ucs1lib_find_max_char((Py_UCS1*)f, (Py_UCS1*)f + len) < 128);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run it once, for the whole format string.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I modified my PR to run it only once, good idea!

@vstinnervstinner enabled auto-merge (squash) June 20, 2024 18:58
@vstinnervstinner merged commit 5150795 into python:mainJun 20, 2024
@vstinnervstinner deleted the optim_from_fmt branch June 20, 2024 19:06
@vstinner
Copy link
MemberAuthor

Merged, thanks for the reviews @serhiy-storchaka.

mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@serhiy-storchaka