[swift-evolution] [Pitch] Retiring `where` from for-in loops

Charlie Monroe charlie at charliemonroe.net
Tue Jun 14 00:01:53 CDT 2016


> On Jun 13, 2016, at 9:59 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>>> See the benchmarks me and Erica have posted here a few days back - even with the lazy accessor, if you decided to use filter(_:), you lost 10+% of performance. Correct way to do this without `where` and without performance penalization is to use guard within the for-in loop.
>> 
>> 10% on a microbenchmark repeater 4000000 times is hardly a justification for going on way or the other.
> 
> You're right: 10% on a microbenchmark isn't the best possible data. If you have better data, we are all ears.

I never said that it's a deal-breaker, but it is definitely something to consider. Since we're discussing performance of the loop itself, you can't perform much in the body of the for loop since it would skew the result (obviously). 

I've previously noted that if/guard-continue come in really close speed-wise, which makes them candidates for a fix-it in case `where` is indeed removed.

My response here was solely to Jean-Daniel's note that he mustn't forget to include the lazy accessor, pointing out that even the lazy accessor is slower than using an inline check.


> 
> -- 
> Brent Royal-Gordon
> Architechies
> 



More information about the swift-evolution mailing list