[swift-evolution] [Review] SE-0007 Remove C-style for-loops with conditions and incrementers

David Owens II david at owensd.io
Thu Dec 10 16:07:53 CST 2015


> On Dec 10, 2015, at 1:57 PM, thorsten--- via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Yes, performance is one thing neglected by the discussions and the proposal.

This is my primary objection to to this proposal; it assumes (or neglects?) that all of the types used can magically be inlined to nothing but the imperative code. This isn’t magical, someone has to implement the optimizations to do this.

Is there any guarantee that these two loops have the exact same runtime performance?

for (i, j) in zip(10.stride(to: 0, by: -1), 20.stride(to: 0, by: -2)) {
   if i % 2 == 0 { continue }
   print(i, j)
}

for var i = 10, j = 20; i > 0 && j > 0; i -= 1, j -= 2 {
   if i % 2 == 0 { continue }
   print(i, j)
}


And can you guarantee that performance is relatively the same across debug and release builds? Because historically, Swift has suffered greatly in this regard with respects to the performance of optimized versus non-optimized builds.

These types of optimizer issues are real-world things I’ve had to deal with (and have written up many blog posts about). I get the desire to simplify the constructs, but we need an escape hatch to write performant code when the optimizer isn’t up to the job.

-David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151210/4ba44edd/attachment.html>


More information about the swift-evolution mailing list