Repository navigation
gh-159037: Improve performance of str.join pre-pass - #159038
Open
eendebakpt wants to merge 3 commits into
Open
eendebakpt wants to merge 3 commits into
eendebakpt wants to merge 3 commits into
Conversation
Compute the maximum character and whether memcpy() can be used from the OR of the item kinds and the AND of their ASCII flags after the pre-pass, instead of per item. Count one separator per item and subtract the extra one after the loop. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ed kinds Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
|
Interesting optimization! I will try to review it next week. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pre-pass of
_PyUnicode_JoinArray()did more work per item than needed. In this PR we now ORs the kinds and ANDs the ASCII flags of the items; the maximum character anduse_memcpyare derived from these after the loop. One separator is counted per item and the extra one is subtracted after the loop. Tests for separators and items of mixed kinds are added.@vstinner
Callgrind confirms the direction: the join function executes 8-18% fewer instructions per call, mostly from dropping the per-item kind comparison.
Benchmark scripts
First table (from the PR 158693):
Second table: