GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-132509: Speed up bytes iteration in FOR_ITER_VIRTUAL by Wulian233 · Pull Request #157353 · python/cpython

Conversation

@Wulian233

@Wulian233 Wulian233 commented Sep 12, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
Benchmark Main PR Throughput improvement
Empty loop 13.858 ns/item 11.850 ns/item 16.9% faster
XOR accumulation 28.195 ns/item 25.409 ns/item 11.0% faster
Conditional count 28.649 ns/item 24.721 ns/item 15.9% faster
Details test script
import statistics
import timeit

DATA = bytes(range(256)) * 4096  # 1 MiB
NUMBER = 10
REPEAT = 11


def loop_pass():
    for byte in DATA:
        pass


def loop_xor():
    result = 0
    for byte in DATA:
        result ^= byte
    return result


def loop_count():
    result = 0
    for byte in DATA:
        if byte == 255:
            result += 1
    return result


BENCHMARKS = (
    ("empty loop", loop_pass),
    ("xor accumulation", loop_xor),
    ("conditional count", loop_count),
)

# Warm up adaptive specialization.
for _, benchmark in BENCHMARKS:
    for _ in range(10):
        benchmark()

print("| Benchmark | Median | Minimum | Median ns/item |")
print("|---|---:|---:|---:|")

for name, benchmark in BENCHMARKS:
    samples = timeit.repeat(
        benchmark,
        number=NUMBER,
        repeat=REPEAT,
    )
    median = statistics.median(samples)
    minimum = min(samples)
    ns_per_item = median * 1e9 / (NUMBER * len(DATA))
    print(
        f"| {name} | {median:.9f} s | "
        f"{minimum:.9f} s | {ns_per_item:.3f} |"
    )
  • Issue: Use tagged pointers for more efficient integer operations. #132509

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Wulian233
pythongh-132509: Speed up bytes iteration in FOR_ITER_VIRTUAL
e1d7206
@Wulian233
Wulian233 requested a review from markshannon as a code owner September 12, 2026 07:03
@bedevere-app bedevere-app Bot mentioned this pull request Sep 12, 2026
Use tagged pointers for more efficient integer operations. #132509
Open
@bedevere-app bedevere-app Bot added the awaiting review label Sep 12, 2026
@BHUVANSH855 BHUVANSH855 mentioned this pull request Sep 18, 2026
test: run PyRift on upstream PR #157353 BHUVANSH855/cpython#2
Open
JelleZijlstra
JelleZijlstra reviewed Oct 20, 2026
View reviewed changes
Comment thread Python/bytecodes.c
Py_ssize_t index = PyStackRef_UntagInt(null_or_index);
_PyObjectIndexPair next_index = Py_TYPE(iter_o)->_tp_iteritem(iter_o, index);
_PyObjectIndexPair next_index;
if (PyBytes_CheckExact(iter_o)) {

@JelleZijlstra JelleZijlstra Oct 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why special-case bytes here specifically? Doesn't seem related to the linked issue either.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra left review comments
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Wulian233 @JelleZijlstra
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.