Currently, efficient iteration over a memory views axis requires indexing. Iterating with a for-in-loop should result in the same code.
Convert the loop in IterationTransform._optimise_for_loop() in Optimize.py, similar to the range optimisation.
Additional idea: for multi-dimensional views, the iteration could yield borrowed slices, with their lifetime bound to the current loop iteration. That would avoid the refcounting overhead for them, which can hurt for very small slices (as found in #2987). Iteration seems to provide a natural frame for this.
Currently, efficient iteration over a memory views axis requires indexing. Iterating with a for-in-loop should result in the same code.
Convert the loop in
IterationTransform._optimise_for_loop()inOptimize.py, similar to therangeoptimisation.Additional idea: for multi-dimensional views, the iteration could yield borrowed slices, with their lifetime bound to the current loop iteration. That would avoid the refcounting overhead for them, which can hurt for very small slices (as found in #2987). Iteration seems to provide a natural frame for this.