Negative prefixed numbers in equations create long compile times

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.

1 Like

CC @xedin @rudkx

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.

Is that fixable?

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.

2 Likes

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?

Terms of Service

Privacy Policy

Cookie Policy