Guig
Guig

Reputation: 10377

XCode 8 is really slow to compile, SourceKitService uses 300+ % CPU

My Xcode is really really slow to compile. The Activity monitor indicates ~330% CPU usage for SourceKitService and 100% for swift. Is there something abnormal going on there?

I've read on a few places that SourceKitService can be struggling guessing arrays and dictionaries types so I'll try to make them more explicits. And since those posts are from Xcode 5-6 I'm wondering if that's still an issue

Upvotes: 0

Views: 693

Answers (1)

Guig
Guig

Reputation: 10377

Thanks @Mike for the link to the build time analyser, it's great. It turned out that XCode take 330 seconds to compile just:

func asJson() -> JSON {
    let dict: [String: Any?] = [
        "video": video.asJson,
        "asset": asset.url.path,
        "canBeShared": canBeShared,
        "videoSource": videoSource.path,
        "previewSource": previewSource.documentPath,
        "expectedResizedVideo": expectedResizedVideo.documentPath,
        "videoDestination": videoDestination,
        "previewDestination": previewDestination,
        "fileId": fileId,
        "isRecordCreated": isRecordCreated,
        "isPreviewUploaded": isPreviewUploaded,
        "isPreviewRegistered": isPreviewRegistered,
        "isSharingPreviewReady": isSharingPreviewReady,
        "isVideoUploaded": isVideoUploaded,
        "isVideoRegistered": isVideoRegistered,
        "isPosted": isPosted,
        "isPostRegistered": isPostRegistered,
        "didResizeVideo": didResizeVideo,
    ]
    return JSON(dict)
}

which I rewrite to

func asJson() -> JSON {
    var dict = [String: Any?]()
    dict["video"] = video.asJson
    dict["asset"] = asset.url.path
    dict["canBeShared"] = canBeShared
    dict["videoSource"] = videoSource.path
    dict["previewSource"] = previewSource.documentPath
    dict["expectedResizedVideo"] = expectedResizedVideo.documentPath
    dict["videoDestination"] = videoDestination
    dict["previewDestination"] = previewDestination
    dict["fileId"] = fileId
    dict["isRecordCreated"] = isRecordCreated
    dict["isPreviewUploaded"] = isPreviewUploaded
    dict["isPreviewRegistered"] = isPreviewRegistered
    dict["isSharingPreviewReady"] = isSharingPreviewReady
    dict["isVideoUploaded"] = isVideoUploaded
    dict["isVideoRegistered"] = isVideoRegistered
    dict["isPosted"] = isPosted
    dict["isPostRegistered"] = isPostRegistered
    dict["didResizeVideo"] = didResizeVideo
    return JSON(dict)
}

and that works just fine. I'll open a bug with Apple

Upvotes: 3

Related Questions