4

I'm trying to make compile time of my project faster. I've read here and other online resources.
My project build settings seems to be correct:

  • Optimization None (just debug)
  • Build only for active architecture YES
  • Compile DWARF

It seems that the compiler slows down when it needs to infer type in pretty chained method, such as string.characters.split{}.map{} and when it needs to add arrays using the + operator.
Using these advices I've reduced the compile time but there is this method that takes about 6 seconds on my machine MBP 15' last model, I really can't figure out why.
Here a piece of the trace:

6102.4ms /../Views/CakeView.swift:221:10 func changeArrowDirection(direction: ArrowDirection, animated: Bool = default)
2463.5ms /../Views/CakeView.swift:71:9 final didSet {}
2189.8ms /../UIComponents/GradientView.swift:47:9 final didSet {}


func changeArrowDirection(direction: ArrowDirection, animated: Bool = false) {
        let radius: CGFloat = min(bounds.size.width / 2.0, bounds.size.height / 2.0)
        let arrowBackgroundLayerRadius: CGFloat = radius / 2.0
        let tailWidth: CGFloat = arrowBackgroundLayerRadius / 4.0
        let headWidth: CGFloat = arrowBackgroundLayerRadius / 1.75
        let headlength: CGFloat = arrowBackgroundLayerRadius / 2.0
        let subArc: CGFloat = cos(asin(1.0 / (2.0 * arrowBackgroundLayerRadius)))

        let startPoint: CGPoint
        let endPoint: CGPoint

        switch direction {
        case .Up:
            startPoint = CGPoint(x: bounds.size.width / 2.0, y: bounds.size.height / 2.5 + arrowBackgroundLayerRadius - arrowBorderWidth - subArc - arrowCircleBorderWidth)
            endPoint = CGPoint(x: bounds.size.width / 2.0, y: bounds.size.height / 1.75  - arrowBackgroundLayerRadius + arrowCircleBorderWidth + arrowBorderWidth)
        case .Down:
            startPoint = CGPoint(x: bounds.size.width / 2.0, y: bounds.size.height / 1.75 - arrowBackgroundLayerRadius + arrowBorderWidth + subArc + arrowCircleBorderWidth)
            endPoint = CGPoint(x: bounds.size.width / 2.0, y: bounds.size.height / 2.5 + arrowBackgroundLayerRadius - arrowCircleBorderWidth - arrowBorderWidth)
        case .Left:
            startPoint = CGPoint(x: bounds.size.width / 2.0 - arrowBackgroundLayerRadius + arrowBorderWidth + subArc + arrowCircleBorderWidth, y: bounds.size.height / 2.0)
            endPoint = CGPoint(x: bounds.size.width / 2.0 + arrowBackgroundLayerRadius - arrowCircleBorderWidth - arrowBorderWidth,y: bounds.size.height / 2.0)
        case .Right:
            startPoint = CGPoint(x: bounds.size.width / 2.0 + arrowBackgroundLayerRadius - arrowBorderWidth - subArc - arrowCircleBorderWidth, y: bounds.size.height / 2.0)
            endPoint = CGPoint(x: bounds.size.width / 2.0 - arrowBackgroundLayerRadius + arrowCircleBorderWidth + arrowBorderWidth,y: bounds.size.height / 2.0)

        }

        arrowLayer.path = UIBezierPath.bezierPathWithArrowFromPoint(startPoint, endPoint: endPoint, tailWidth: tailWidth, headWidth: headWidth, headLength: headlength).CGPath
    }

Can someone spot the reason?

Community
  • 1
  • 1
Andrea
  • 26,120
  • 10
  • 85
  • 131

0 Answers0