Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commented Dec 17, 2025

Now that we specialize range iteration in the interpreter, there's not a significant performance cost to making the iteration thread-safe.

Now that we specialize range iteration in the interpreter for the common case where the iterator has only one reference, there's not a significant performance cost to making the iteration thread-safe.
@colesbury
Copy link
ContributorAuthor

https://github.com/facebookexperimental/free-threading-benchmarking/tree/main/results/bm-20251216-3.15.0a3+-afd3eff-CLANG,NOGIL shows 1.001x faster, which I think is just noise.

I also ran https://github.com/colesbury/fastbench/ locally:

  • No measurable difference in performance
  • rangeiter_next is hit 40,000 times.
  • Some of those are pre-specialization. Most of them are fromlist.extend(range(...)).
  • At ~10 ns overhead per critical section and 13.1 seconds benchmark run time, that's about 0.003% extra overhead

FWIW, I used Codex to convert rangeobject.c to Argument Clinic and it worked pretty well.

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

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

LGTM

@colesburycolesbury merged commit f54d44d into python:mainDec 18, 2025
83 of 85 checks passed
@colesburycolesbury deleted the gh-129068-rangeiter-next branch December 18, 2025 18:11
cocolato pushed a commit to cocolato/cpython that referenced this pull request Dec 22, 2025
Now that we specialize range iteration in the interpreter for the common case where the iterator has only one reference, there's not a significant performance cost to making the iteration thread-safe.
Sign up for freeto 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

@colesbury@kumaraditya303