News for hackers. Stuff that matters.
Re:Writing a winning 4K intro in Rust by gavinray on Sunday July 05, 2020 @10:29PM (#23744111)
There are tricks/an art to Rust's iterator semantics.

One example I know of is that when trying to calculate a dot product, you can improve the generated code and elide the bounds check only by a very particular syntax:

    // Must slice to equal lengths, and then bounds checks are eliminated!
    let len = cmp::min(xs.len(), ys.len());
    let mut xs = &xs[..len];
    let mut ys = &ys[..len];
    let mut s = 0.;
    for i in 0..xs.len() {
        s += xs[i] * ys[i];
    }
https://users.rust-lang.org/t/how-to-zip-two-slices-efficien...

https://github.com/rustsim/nalgebra/blob/b1b18d17ee64d3fd28b...

Re:Writing a winning 4K intro in Rust by bad-apple on Monday July 06, 2020 @03:12AM (#23745460)
Does it still elide the bounds check if you replace the first three lines with

    assert_eq!(xs.len(), ys.len());

?