Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big negative impact on compilation time #25

Open
APesate opened this issue May 12, 2017 · 4 comments
Open

Big negative impact on compilation time #25

APesate opened this issue May 12, 2017 · 4 comments

Comments

@APesate
Copy link

APesate commented May 12, 2017

After running a profiling script to check the compilation times of the project (because it began to be really slow) I noticed that the methods where I set up the constraints with this library are the ones that take the longest to compile and it's making the project to take between 4 - 5 min to run. The project is really small so it shouldn't be the case.

This is the method that takes the longest to compile. 56690.86ms

fileprivate func setupConstraints() {
        playerComponentView.translatesAutoresizingMaskIntoConstraints = false
        headerComponentView.translatesAutoresizingMaskIntoConstraints = false
        tabsComponentView.translatesAutoresizingMaskIntoConstraints = false
        componentsScrollView.translatesAutoresizingMaskIntoConstraints = false
        topHeaderView.translatesAutoresizingMaskIntoConstraints = false
        closeButton.translatesAutoresizingMaskIntoConstraints = false
        chromecastButton.translatesAutoresizingMaskIntoConstraints = false
        topTitleLabel.translatesAutoresizingMaskIntoConstraints = false

        if UIDevice.current.userInterfaceIdiom == .pad {
            addConstraints([componentsScrollView.width == width * 0.7,
                            componentsScrollView.top == top,
                            componentsScrollView.bottom == bottom,
                            componentsScrollView.centerX == centerX])
        } else {
            addConstraints([componentsScrollView.leading == leading,
                            componentsScrollView.top == top,
                            componentsScrollView.bottom == bottom,
                            componentsScrollView.trailing == trailing])
        }

        let playerHeight = (((UIScreen.main.bounds.height * 0.7) * 9) / 16)
        addConstraints([playerComponentView.leading == componentsScrollView.leading,
                        playerComponentView.trailing == componentsScrollView.trailing,
                        playerComponentView.top == componentsScrollView.top,
                        playerComponentView.height == playerHeight,
                        playerComponentView.width == componentsScrollView.width])

        addConstraints([headerComponentView.top == playerComponentView.bottom,
                        headerComponentView.leading == componentsScrollView.leading,
                        headerComponentView.trailing == componentsScrollView.trailing,
                        headerComponentView.width == componentsScrollView.width])

        addConstraints([tabsComponentView.leading == componentsScrollView.leading,
                        tabsComponentView.trailing == componentsScrollView.trailing,
                        tabsComponentView.top == headerComponentView.bottom,
                        tabsComponentView.bottom == componentsScrollView.bottom,
                        tabsComponentView.width == componentsScrollView.width])

        topHeaderBottomConstraint = (topHeaderView.bottom == top)

        addConstraints([topHeaderBottomConstraint,
                        topHeaderView.leading == componentsScrollView.leading,
                        topHeaderView.trailing == componentsScrollView.trailing])

        let buttonsTopMargin = (UIApplication.shared.statusBarFrame.height + 8)

        addConstraints([closeButton.trailing == topHeaderView.trailing - 8,
                        closeButton.top == top + buttonsTopMargin,
                        closeButton.width == 48,
                        closeButton.height == 48])

        addConstraints([chromecastButton.trailing == closeButton.leading - 8,
                        chromecastButton.top == closeButton.top,
                        chromecastButton.width == 48,
                        chromecastButton.height == 48])

        addConstraints([topTitleLabel.leading == topHeaderView.leading + DetailsViewDesignGuidelines.contentMargin,
                        topTitleLabel.trailing == chromecastButton.leading - 8,
                        topTitleLabel.top == topHeaderView.top + (UIApplication.shared.statusBarFrame.height + 20),
                        topTitleLabel.bottom == topHeaderView.bottom - 16])
}

By changing the constraints configuration to use NSLayoutConstraint directly it goes down to 10.56ms As you can see is quite difference.

Any ideas on what could be the problem or how to fix this? I would really like to continue using this library because it makes so much easier and faster the constraints setup, but the impact it has on the build time is just too big and it will only get worse as the project gets bigger.

@carmelogallo
Copy link

I can only confirm what @APesate said. Same problem for me.

@indragiek
Copy link
Owner

This is a known issue with the compiler taking too long to resolve complex expressions. Unfortunately I don't have a solution for this until this is improved in the compiler.

@carmelogallo
Copy link

@indragiek I tried this other option, https://github.com/Raizlabs/Anchorage, sorry about that.

Anyway, the same code above goes from 56690.86ms to 580.65ms and the are using also complex expression. Maybe would be nice if you take a look and see what could be wrong.

I found a case were the compilation time is increased a lot:
addConstraint(someView.top == view.top + 5.0 + 10.0 + 40.0)
Here just because we are using multiple operation ( + 5.0 + 10.0 + 40.0 ) the compiler needs 5 secs to compile.

@rikumi
Copy link

rikumi commented Jul 12, 2017

I found a case were the compilation time is increased a lot:
addConstraint(someView.top == view.top + 5.0 + 10.0 + 40.0)

Why not make the priority of the '+' operator between 'view.top' and '5.0' a little bit lower? This will let '5.0 + 10.0 + 40.0' be calculated first into 55.0 and turn 3 constraint-relative operations into 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants