News for hackers. Stuff that matters.
Re:Rust Performance Pitfalls by pcwalton on Thursday June 08, 2017 @03:24PM (#14516476)
Because in the former case, the optimizer has to prove that the length of the array cannot change during the body of the loop, while in the latter case, that's guaranteed by the language semantics.
Re:Rust Performance Pitfalls by masklinn on Thursday June 08, 2017 @03:38PM (#14516604)
Also because the iterator could do something completely different from an iteration by sequential index no?
Re:Rust Performance Pitfalls by mindleyhilner on Thursday June 08, 2017 @07:15PM (#14517924)
Doesn't `let x = xs[i]` immutably borrow from xs? So for the duration of x's lifetime (which is the entire for-body block), xs cannot be changed and therefore its length must remain the same.

Though this might be information that rustc knows about but not LLVM.

Re:Rust Performance Pitfalls by pcwalton on Thursday June 08, 2017 @07:31PM (#14518014)
In the case of "let x = &xs[i]" it would immutably borrow. But we'd need more MIR optimizations to make use of that fact.