swiftbuild-time

Rules for type check in Swift builds?


I’ve wanted to speed up my build times, so one of the steps was using Other Swift Flags and

-Xfrontend -warn-long-function-bodies=100
-Xfrontend -warn-long-expression-type-checking=100


But I’m not really sure how type checks work. For example, here’s a simple func for creating random CGFloat. Type check for it is over 200ms

static func randomColorValue() -> CGFloat {
    return CGFloat(Int.random(in: 0...255))/255.0
}

But on changing to something like this

  static func randomColorValue() -> CGFloat {
         let rnd    = Int.random(in: 0...255)
         let frnd   = CGFloat(rnd)
         let result = frnd/255.0

         return result
     }

or like this

static func randomColorValue() -> CGFloat {
     let rnd    : Int     = Int.random(in: 0...255)
     let frnd   : CGFloat = CGFloat(rnd)
     let result : CGFloat = frnd/255.0

     return result
 }

type check is still over 200ms.


What's wrong here? Is there any set of rules and best practices for dealing with build times? My Mac is a bit older (2012), maybe that's the problem?


EDIT:

After turning off -warn-long-function-bodies problematic line appeared, and that is

CGFloat(rnd)

It appears that casting Int to Float, Double or CGFloat shows slowing down of 150ms.


Solution

  • Note that warn-long-function-bodies is unsupported (it was added as an experimental flag). If you remove it, I find that the expression time is often reported as twice as fast, which makes be believe that using the two measurements together is causing interference. Measurement takes time, too. warn-long-expression is a supported option.