Is there a clear syntax for iterating multiple iterators at once?

The state of the art in zipping performance is unfortunately the method mentioned in How to “zip” two slices efficiently; slice them to the same length and index iterate. Even the unsafe-using ZipSlices which was as good has regressed in recent rust and does not generate optimal or vectorizable code due to rustc/llvm codgen issues.

Anyway, here's a good rule: If you use the slice's length as loop counter bound, then llvm will remove bounds checks inside the loop. It's logical. You just have to make sure to use something that llvm sees is identical with the slice length.

I haven't verified that the trick works with three or more slices, probably does?

1 Like