I have compiler flags setup in Other Swift Flags to notify me of any funcs that take a long time to compile. Whenever I have an equation with a negative value (ex. -self.size.width / 2) the compile time increases drastically. If I prefix the negative number with a "0 -" (ex. 0 - self.size.width / 2) compile times go back to normal.
It won't let me add more than one image, showing that the second function had a really high compile time as well.
I apologize for the func name in my image, it was created when showing some friends the issue.
I think I know why. There are shortcuts in the compiler that prefer operators on concrete types. Binary
- is defined on all integer types precisely because of this. Unary prefix
-, however, is only defined in an extension to
SignedNumeric protocol here.
Short term we can add more overloads, as we used to do up until now. Long-term @xedin is working on improvements in this area.
This is appreciated. This severely affects SpriteKit developers more than iOS developers in my opinion. In SpriteKit all our objects are created by default with a Center anchor point resulting in many of our calculations having to use the negative values like in my code example above.
Hi @moiseev, any updates on this?