Skip to content

perf(iteration): use move instead of clone for iteration#1586

Merged
akern40 merged 2 commits intorust-ndarray:masterfrom
akern40:adam/no-clone
Feb 16, 2026
Merged

perf(iteration): use move instead of clone for iteration#1586
akern40 merged 2 commits intorust-ndarray:masterfrom
akern40:adam/no-clone

Conversation

@akern40
Copy link
Collaborator

@akern40 akern40 commented Feb 16, 2026

@scho-furiosa pointed out in #1584 that there was an unnecessary clone in Baseiter::next that was degrading performance for dynamic-dimensional arrays. This change switches to a move, netting a 74% speedup in iteration for dynamic-dimensional arrays.

Tests (detailed in #1584) showed that there was a trade-off in performance between dynamic- and fixed-dimensional iteration. ArrayD performs best when mutating its index; ArrayN performs best when using a move. This is an indication that, in the future, Baseiter::next should dispatch to the "layout" / Dimension underlying type.

@akern40 akern40 enabled auto-merge (squash) February 16, 2026 14:14
@akern40 akern40 disabled auto-merge February 16, 2026 14:14
@akern40 akern40 enabled auto-merge (squash) February 16, 2026 14:14
@akern40 akern40 merged commit 27af864 into rust-ndarray:master Feb 16, 2026
15 checks passed
@akern40 akern40 deleted the adam/no-clone branch February 16, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant