-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
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, sincerangecould have been changed by a user to a custom implementation. rangeis 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.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
type-featureA feature request or enhancementA feature request or enhancement