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

Fix Vertical Whitespace Rule performance issue and make it not opt-in #772

Closed
dcaunt opened this issue Aug 24, 2016 · 6 comments · Fixed by #775
Closed

Fix Vertical Whitespace Rule performance issue and make it not opt-in #772

dcaunt opened this issue Aug 24, 2016 · 6 comments · Fixed by #775
Labels
bug Unexpected and reproducible misbehavior.

Comments

@dcaunt
Copy link

dcaunt commented Aug 24, 2016

Swiftlint 0.11.2 hangs on my project (while 0.11.1 does not) when linting a file. I've pared down the file as much as possible to make it easier to identify the bug. I couldn't see a way to run swiftlint in a verbose mode to debug further.

// AppDelegate.swift


import Foundation
import SuperDelegate
import Fabric
import Crashlytics
import WebImage
import FBSDKMessengerShareKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: SuperDelegate, ApplicationLaunched, CrashStatusStorage {

    var dependencies: AppDependencies!

    func setupApplication() {
        // Required for SDWebImage to follow 302 redirects
        SDWebImageDownloader.sharedDownloader().setValue("text/html,image/*;q=0.8", forHTTPHeaderField: "Accept")
    }

    func loadInterfaceWithLaunchItem(launchItem: LaunchItem) {
        FBSDKApplicationDelegate.sharedInstance().application(UIApplication.sharedApplication(), didFinishLaunchingWithOptions: launchItem.launchOptions)

        dependencies.installRootViewControllerIntoWindow(window)

        switch launchItem {
        case let .OpenURLItem(urlToOpen):
            break

        case let .UserActivityItem(userActivity):
            continueUserActivity(userActivity, restorationHandler: { (_) in
                // Nothing to do here.
            })

        case let .RemoteNotificationItem(remoteNotification):
            break
        case .NoItem:
            // We were launched from Springboard or the App Switcher.
            break
        default:
            break
        }
    }
}
@jpsim
Copy link
Collaborator

jpsim commented Aug 24, 2016

Looks like a performance regression in 0.11.2. Thanks for reporting this.

Note that SwiftLint 0.11.2 does complete when linting your file, it just takes much longer than it should.

This is why having performance benchmarks/tests would be immensely useful (#376).


I couldn't see a way to run swiftlint in a verbose mode to debug further.

swiftlint lint --benchmark will output 2 files: benchmark_files.txt and benchmark_rules.txt that breaks down how much time was spent in each file and in each rule, respectively.

It turns out that the vertical whitespace rule is the culprit:

0.000: file_length
0.000: leading_whitespace
0.000: trailing_whitespace
0.000: custom_rules
0.000: type_body_length
0.000: closing_brace
0.000: todo
0.000: force_try
0.000: statement_position
0.000: legacy_constant
0.000: legacy_constructor
0.000: private_unit_test
0.000: function_parameter_count
0.000: legacy_cggeometry_functions
0.000: return_arrow_whitespace
0.000: operator_whitespace
0.000: force_cast
0.000: function_body_length
0.000: trailing_semicolon
0.000: variable_name
0.000: line_length
0.000: cyclomatic_complexity
0.000: control_statement
0.000: valid_docs
0.000: nesting
0.000: mark
0.000: trailing_newline
0.000: legacy_nsgeometry_functions
0.000: opening_brace
0.001: type_name
0.001: comma
0.001: colon
66.121: vertical_whitespace

Also, since SwiftLint is an Xcode project, you can easily run it with Instruments and/or debug it with LLDB to identify issues.

@jpsim jpsim changed the title Hang while linting file Vertical Whitespace Rule performance issues Aug 24, 2016
@jpsim jpsim closed this as completed in f559abb Aug 24, 2016
@jpsim
Copy link
Collaborator

jpsim commented Aug 24, 2016

Fixed in f559abb. Cutting 0.12.0 now to push this out to everyone asap.

@jpsim
Copy link
Collaborator

jpsim commented Aug 24, 2016

I'll reopen this to track fixing the actual performance issue and no longer making the rule opt-in.

@jpsim jpsim reopened this Aug 24, 2016
@jpsim jpsim changed the title Vertical Whitespace Rule performance issues Fix Vertical Whitespace Rule performance issue and make it not opt-in Aug 24, 2016
@jpsim
Copy link
Collaborator

jpsim commented Aug 24, 2016

@masters3d do you think you could address this?

@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Aug 24, 2016
@masters3d
Copy link
Contributor

I'll take a look

@masters3d
Copy link
Contributor

I'll submit a PR momentarily.
/* in the file is tripping the regex to match multiline comments :(

SDWebImageDownloader.sharedDownloader().setValue("text/html,image/*;q=0.8", forHTTPHeaderField: "Accept")
let matchMultilineComments = "/\\*(.|[\\r\\n])*?\\*/"

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

Successfully merging a pull request may close this issue.

3 participants