Swift 1.0 – some caution recommended

In my last blog entry I expressed some concern about the performance bugs in compilation and runtime that keep popping up.

Since Scala is a bit infamous for slow compilation times – partly attributed to type inference – my fear has been that Swift would remain fairly slow at compilation. However, I’ve been assured that Swift’s model is much closer to that of F# and C#. The current O(n²) compiler times are due to bugs and not due to any inherent complexity in the language itself.

That said, everyone should keep a few things in mind when considering Swift for a project:

Swift 1.0 / Xcode 6.0

  1. Compile times appear roughly quadratic with 10k LOC typically taking 20-30 seconds to complete. If your project is likely to exceed 5000 lines, consider ObjC instead.
  2. Code completion and editing experience severe performance problems for larger projects, e.g. 10k LOC and over
  3. There are various bugs in corner cases when bridging between ObjC / Swift. Check on the devforums for workarounds.
  4. Calling something in the same file can yield large performance benefits compared to from another file.
  5. Swift is not tracking dependencies between files, so changing a single file cause a full recompilation of all Swift files.
  6. It’s possible to keep compile times down somewhat by splitting a project into frameworks.

Swift 1.1 / Xcode 6.1

  1. Xcode 6.1 beta 1 compilation is just as slow as 6.0 but we might see some improvements to this in later betas.
  2. Future 6.1 betas will see performance improvements to Code Completion / Editing, but 6.1b1 has the same issues as 6.0.
  3. Bugs in corner cases are likely to keep popping up, so keep on the lookout for any problems with unusual performance hits (and please file a radar if you run into one!)
  4. The cross file issues persist in 6.1b1, it’s not known if this will be fixed in 6.1 but at least the compiler team appears to be working on the issue.
  5. Swift will eventually track file dependencies, but there are no indications that this will be added to 6.1 yet.

 

6 thoughts on “Swift 1.0 – some caution recommended

  1. Hey Christoffer, I was wondering if you could elaborate more about the solution for high compile time problem. Maybe point me somewhere where I can learn more about it? I’m working on a medium sized Swift/ObjC project that takes approx. 3 minute to recompile even on quad i7 when a single file has been changed..

    Like

    • There is not real solution for the long compile times. We rewrote our entire project in ObjC (which in hindsight is looking better and better) to “fix” the problem.

      As for splitting the project into components – I haven’t tried to split the project into multiple modules myself. For details it’s probably better to head over to the apple devforum for Swift and ask.

      Like

  2. I found a temporary solution to the problem, I created a new target in the project with all ObjC files and just one .swift file, then with a pre-action in the Build, I append all swift files content into that swift file. Then Xcode just has one swift file to compile. It reduced my compilation time from 30 seconds to 10 seconds. Here’s the gist: https://gist.github.com/lucholaf/e37f4d26e406250a156a

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s