Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Python range object for small integers #100726

Closed
eendebakpt opened this issue Jan 3, 2023 · 1 comment
Closed

Optimize Python range object for small integers #100726

eendebakpt opened this issue Jan 3, 2023 · 1 comment
Labels
performance Performance or resource usage type-feature A feature request or enhancement

Comments

@eendebakpt
Copy link
Contributor

eendebakpt commented Jan 3, 2023

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

@eendebakpt eendebakpt added the type-feature A feature request or enhancement label Jan 3, 2023
@Fidget-Spinner Fidget-Spinner added the performance Performance or resource usage label Jan 4, 2023
mdickinson added a commit that referenced this issue Jan 21, 2023
…egers (#100810)

Use C long arithmetic instead of PyLong arithmetic to compute the range length, where possible.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Mark Dickinson <[email protected]>
@mdickinson
Copy link
Member

Closed in #100810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants