sprs icon indicating copy to clipboard operation
sprs copied to clipboard

Usage of zip in products may be inefficient

Open vbarrielle opened this issue 8 years ago • 1 comments

As explained here, using zip to iterate on members with the same length is inefficient bacause the compiler won't be able to remove both bounds checkings.

Some tricks exist for slices, but here the situation is somewhat different, maybe an unsafe block (or a dedicated primitive implemented as unsafe) is necessary.

vbarrielle avatar Jan 17 '16 19:01 vbarrielle

This may be no longer relevant as the above linked issue was updated in 2017,

Rust now implements .zip() specially for a couple of core iterators, including slice iterators (iter and iter_mut) as well as a few adaptors of those (map, cloned, zip, maybe more). For these iterators zip will now provide satisfactory loop optimization, for example allowing for auto-vectorization of certain loops.

rth avatar Jun 22 '20 11:06 rth