You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The range object is often used in python code. The current implementation is already efficient for integers that fit into a C long, but can be improved. The most performance critical use case is probably with a single-argument in a for loop like:
for x in range(N):
...
For that case we can avoid several conversions of Python integers to C long and a construction of a new Python integer by adding a fast path for the single argument case (e.g. start=0 and step=1).
Alternative ideas:
Modify the interpreter to change in range(...) in a direct construction of the iterable (skipping the range object). This would be hard to implement backwards compatible, since range could have been changed by a user to a custom implementation.
range is read-only, so we could construct an iterable with a reference to the range object to save memory. Since the current iterable (_PyRangeIterObject) is already very small, it seems unlikely this will gain something.
Activity
gh-116477: Improve performance of `range()` when `start` is 0 and `st…