Skip to content

Optimize Python range object for small integers #100726

Description

@eendebakpt

Feature or enhancement

The python range object contains code to compute the length from the start, stop and step values. This calculation is performed with PyLong objects which is expensive. We can add a fast path for the common case where start, stop and step all fit into a long value.

Pitch

Benchmark results are in the PR.

The range object itself is often converted to a range iterator. For the iterator object there already is a fast version (the the method fast_range_iter). A further optimization could be achieved by creating a specialized range object that can construct the fast range iterator without conversions to PyLong, but this is much more involved.

Linked PRs

Activity

  1. added a commit that references this issue on Jan 21, 2023
  2. mdickinson commented on Jan 21, 2023

    @mdickinson
    Member

    Closed in #100810

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions