FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-158585: Optimize bytes.join() for non-empty separator by vstinner · Pull Request #158689 · python/cpython · GitHub

Repository navigation

gh-158585: Optimize bytes.join() for non-empty separator - #158689

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:bytes_join
Oct 5, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:bytes_join

Conversation

vstinner commented Oct 3, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

vstinner commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

Benchmark:

import pyperf
runner = pyperf.Runner()
for list_size in ('10', '10**3', '10**6'):
    runner.timeit(
        f'short items: {list_size}',
        setup=f"data=[b'x']*{list_size}; sep=b'.'",
        stmt="sep.join(data)")

for list_size in ('10', '10**2', '10**4'):
    runner.timeit(
        f'long items: {list_size}',
        setup=f"data=[b'x' * 100]*{list_size}; sep=b'.'",
        stmt="sep.join(data)")

Results on Fedora 44 with CPU isolation:

Benchmark ref change
short items: 10 215 ns 206 ns: 1.04x faster
short items: 10**3 16.7 us 15.5 us: 1.08x faster
short items: 10**6 63.0 ms 62.6 ms: 1.01x faster
long items: 10 294 ns 282 ns: 1.04x faster
long items: 10**2 1.83 us 1.75 us: 1.05x faster
Geometric mean (ref) 1.03x faster

Benchmark hidden because not significant (1): long items: 10**4

vstinner commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

See also #158693 which optimizes PyUnicode_Join().

eendebakpt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Small change and a nice improvement. While investigating this I found there are larger gains possible in case of exact bytes (the common case?), but also a bug in the FT build (I created #158803).

vstinner merged commit fc3cd8e into python:main Oct 5, 2026
59 checks passed
vstinner deleted the bytes_join branch October 5, 2026 11:51

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Merged, thanks for your review @eendebakpt.

While investigating this I found there are larger gains possible in case of exact bytes (the common case?)

Do you mean not avoiding Py_buffer or something else? If you have an idea, please propose a pull request with a benchmark and put me in copy. I will review it :-)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL