gh-144569: Avoid creating temporary objects in BINARY_SLICE for bytes - #156318
Open
koxudaxi wants to merge 2 commits into
Open
gh-144569: Avoid creating temporary objects in BINARY_SLICE for bytes#156318koxudaxi wants to merge 2 commits into
BINARY_SLICE for bytes#156318koxudaxi wants to merge 2 commits into
Conversation
koxudaxi
requested review from
Fidget-Spinner,
markshannon,
savannahostrowski and
tomasr8
as code owners
August 24, 2026 14:37
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.
Add an exact
bytesfast path toBINARY_SLICE, following the list, tuple, and unicode fast paths added in gh-144590. This avoids creating a temporarysliceobject. Bytes subclasses continue to use the generic path.Teach the Tier 2 optimizer that slicing an exact
bytesobject returns an exactbytesobject.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.
base64.b64encodewithaltchars, 3 million operationsThere 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_bytesandtest_slicealso passed a-R 3:3refleak run.