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

gh-144569: Avoid creating temporary objects in `BINARY_SLICE` for bytes by koxudaxi · Pull Request #156318 · python/cpython · GitHub

/ cpython Public

gh-144569: Avoid creating temporary objects in BINARY_SLICE for bytes - #156318

Open
koxudaxi wants to merge 3 commits into
python:mainfrom
koxudaxi:gh-144569-bytes-binary-slice
Open

gh-144569: Avoid creating temporary objects in BINARY_SLICE for bytes#156318
koxudaxi wants to merge 3 commits into
python:mainfrom
koxudaxi:gh-144569-bytes-binary-slice

Conversation

koxudaxi commented Aug 24, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Add an exact bytes fast path to BINARY_SLICE, following the list, tuple, and unicode fast paths added in gh-144590. This avoids creating a temporary slice object. Bytes subclasses continue to use the generic path.

Teach the Tier 2 optimizer that slicing an exact bytes object returns an exact bytes object.

Benchmark

Release builds on macOS arm64. Each result is the median of nine alternating runs after two warmups. Each sample ran in a fresh process.

Benchmark main this PR Change
Partial bytes slice, 5 million operations 347.717 ms 310.204 ms 10.8% faster
Full bytes slice, 5 million operations 274.867 ms 246.176 ms 10.4% faster
base64.b64encode with altchars, 3 million operations 562.155 ms 533.675 ms 5.1% faster

There was no measurable change in peak RSS.

Tests

The full debug test suite passed with 50,671 tests using 14 workers.

Focused tests passed on debug, free-threaded, and JIT builds. test_bytes and test_slice also passed a -R 3:3 refleak run.

cocolato left a comment

Copy link
Copy Markdown
Member

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

Looks good!

Copy link
Copy Markdown
Member

@markshannon gentle ping, please take a look at this if you have time, thanks!

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