Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a simple Swift arithmetic operation compile so slow?

In an attempt to optimize the build time of my app I've added the following to my OTHER_SWIFT_FLAGS:

OTHER_SWIFT_FLAGS = 
-Xfrontend -warn-long-expression-type-checking=75
-Xfrontend -warn-long-function-bodies=75

I got a warnings for this specific type checking being slow, and I cannot figure out if I can help the compiler in some way here.

var delay: TimeInterval = TimeInterval(index) * 0.05

Any suggestions what can be done to speed up the compile time for such basic arithmetic operations up?

I'm running Xcode 11.5 with Swift 5

Xcode screenshot

Also tried explicitly casting the number to TimeInterval, which shouldn't be needed as all numbers are Doubles by default. enter image description here

like image 702
Groot Avatar asked Sep 06 '25 13:09

Groot


1 Answers

The compiler performs type checks. If you have a long expression, it takes time. Sometimes when the expression is too long, you even get an error as:

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

try something like

var delay: TimeInterval = TimeInterval(index) * TimeInterval(0.05)
like image 105
Tomo Norbert Avatar answered Sep 08 '25 10:09

Tomo Norbert