<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This is probably a better discussion for swift-users. It sounds like you didn't build with optimization enabled—try that before making any performance measurements.<div class=""><br class=""></div><div class="">-Joe<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 28, 2016, at 7:05 AM, Biala via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div style="background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px;" class=""><div id="yui_3_16_0_ym18_1_1459171693679_6550" class="">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" class="">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. </div><div id="yui_3_16_0_ym18_1_1459171693679_6550" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">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" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">After profiling here is what I see:</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">1. slow arrays - may be partly improved using UnsafeMuttablePointers</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">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" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">array[i] = value </div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">Double(1)</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">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" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">if v in (0...127)</div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class="">I suppose that the range will be also created and then deallocated in background. </div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div><div id="yui_3_16_0_ym18_1_1459171693679_6550" dir="ltr" class=""><br class=""></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>