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

Special optimization for for in range #515

Open
kengorab opened this issue Dec 6, 2024 · 0 comments
Open

Special optimization for for in range #515

kengorab opened this issue Dec 6, 2024 · 0 comments
Labels

Comments

@kengorab
Copy link
Owner

kengorab commented Dec 6, 2024

The builtin range function (which returns a RangeIterator, a type capable of providing a sequence of numbers from a starting value to an ending value which increments by a certain amount (1, by default).

This construction is nice because it offers a lot of flexibility in creating ranges, and offers a nice function-like interface which is easy to understand (named arguments can even be used for clarity). But necessitating the instantiation of a RangeIterator (and calling that instance's next() method for each iteration of the loop) is pretty wasteful.

Instead, there could be an AST transformation which would transform such a construct into a highly-optimized while-loop instead without the need to construct a RangeIterator, and without the need to call its next() method each time. The range function would still be available if such behavior were desired, but this simple optimization would make it feel better when reaching for a for in range() as opposed to a traditional while-loop with an incrementing integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant