<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym18_1_1459171693679_6550">After few days playing with the profiler I have noticed some shocking swift behaviour.</div><div id="yui_3_16_0_ym18_1_1459171693679_6550">When casting basic types from one type to another, for example from Int to Double swift is actually creating and then deallocating something :( That leads to another performance problem - imagine many casts in loops.&nbsp;</div><div id="yui_3_16_0_ym18_1_1459171693679_6550"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">As a type strict language swift is forcing one to cast Int to Double to when you multiply double by Int variables for example but as the cast is so expensive what should developers do to get better performance for some bit of code. As a sound processing developer I see most of the real time sound processing moved to C++ code, but I don,t see the reason for that as it is most basic operations in loops. Swift needs to be faster to become serious language ...</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">After profiling here is what I see:</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">1. slow arrays - may be partly improved using UnsafeMuttablePointers</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">2. expensive cast - this is not possible to avoid at this point. I will suggest making the language not so type strict when there is no need (like adding int to double and so on)</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">array[i] = value&nbsp;</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">Double(1)</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">These problems come from hidden function calls so please avoid adding more of them in future like the syntax Erica suggested for the if:</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">if v in (0...127)</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr">I suppose that the range will be also created and then deallocated in background. &nbsp;</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr"><br></div></div></body></html>