Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is NSISEngine?

Tags:

ios

swift

I'm going through my app and I've noticed that when I load certain (4 out of 112 to be exact) objects and load it into a ViewController with 4 UIStackViews all written with code (i.e no xib) there is a noticeable lag when loading, and specifically when loading the UIStackViews. I ran a performance trace and notice the only difference between the views that load quickly and the ones that lag is NSISEngine methods being called taking about 6x longer (specifically [NSISEngine Optimize]). Does anyone know why this would only pop up for < 5% of cases?

  • Amount of data for each object doesn't matter since there are large objects that don't have this problem.
  • I am using custom UIStackViews that are expandable when tapped and this is the code I'm using:

     func toggle() {
        // only toggle if there's a subView
        guard subView != nil else {
            return
        }
        let rotation = isExpanded ? 0 : π / 2
        isExpanded = !isExpanded
        setSpacing(for: self) // this takes 1e-6s 
        t1 = Date()
        UIView.animate(withDuration: kExpansionTime, animations: {
            self.arrowView.transform = CGAffineTransform(rotationAngle: rotation)
            self.subView?.isHidden = !self.isExpanded
            self.layoutIfNeeded() // no change if this is removed.
        }) {_ in
            t2 = Date()
            print(t2.timeIntervalSince(t1)) // prints ~1s on bad cases and 1e-3 normally
        }
    }  
    

Edit: This doesn't happen on iOS 10, only in iOS 9 (could this be a bug)?

like image 613
uti0mnia Avatar asked Dec 17 '16 21:12

uti0mnia


1 Answers

If anyone was curious as to what was causing they optimization issue, I was using a UILabel with numberOfLines = 0. The Label was in a StackView that had the following properties

stackView.axis = .vertical
stackView.alignment = .center
stackView.distribution = .fillProportionally

I switched the numberOfLines = 1 and it fixed it.

like image 174
uti0mnia Avatar answered Oct 11 '22 01:10

uti0mnia