wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

DeserializeOperation taking 5s to compile #86

Closed kurko closed 8 years ago

kurko commented 8 years ago

When I compiled using the following line, I discovered that a Spine function is at the top of the list of things taking the longest.

xcodebuild -workspace myApp.xcworkspace -scheme myApp clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep [1-9].[0-9]ms | sort -nr > culprits.txt

Not sure why it's duplicated, though, but the times are different...

3025.6ms    /Users/MyUser/myApp/Pods/Spine/Spine/DeserializeOperation.swift:338:15  private func resolveRelations()
2933.1ms    /Users/MyUser/myApp/Pods/Spine/Spine/DeserializeOperation.swift:338:15  private func resolveRelations()

Not sure how to fix it, just thought I'd share the finding.

wvteijlingen commented 8 years ago

It seems that type inference is the culprit here (as it usually is). Adding a explicit ResourceIdentifier type for the link parameter fixes this:

let targetResources = linkage.flatMap { (link: ResourceIdentifier) in
    return self.resourcePool.filter { $0.resourceType == link.type && $0.id == link.id }
}
wvteijlingen commented 8 years ago

I've pushed an update. Can you check if this is solved?

kurko commented 8 years ago

Yes. I'll check.