# \`swift run\` really slow

**URL:** <https://forums.swift.org/t/swift-run-really-slow/67807>\
**Category:** Using Swift\
**Created:** [October 12, 2023, 2:33pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807 "2023-10-12T14:33:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![merlindru](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/merlindru/32/32096_2.png) [@merlindru](https://forums.swift.org/u/merlindru)\
**Post date:** [October 12, 2023, 2:33pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/1 "2023-10-12T14:33:44Z")

</div>

Hi! I'm new to Swift development 🙂

Using `swift run` is really slow for me whereas `swift build` and then running the binary isn't. Why is that?

Note that I'm using VSCode + the swift CLI, not xcode

`swift run` takes 3-ish seconds:

```sh
$ time swift run
Building for debugging...
Build complete! (0.09s)
Hello world
swift run 0.09s user 0.06s system 4% cpu 3.345 total

```

`swift build` and manually running takes 0.4s:

```sh
$ time (swift build && ./.build/debug/api)
Building for debugging...
Build complete! (0.08s)
Hello world
( swift build && ./.build/debug/api; ) 0.00s user 0.00s system 0% cpu 0.427 total

```

Am I doing anything wrong? I'm on MacOS 14.0

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [October 12, 2023, 3:46pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/2 "2023-10-12T15:46:43Z")

</div>

> [@merlindru](#):
>
> `swift run 0.09s user 0.06s system 4% cpu 3.345 total`

I don't use the command myself, but it appears `swift run` is a wrapper which invokes lots of other commands to do real work. You can run `swift run --vv` to see the details and perhaps find which child process it spends most of the time waiting for on your system.

---

<div class="post-metadata">

**Author:** ![merlindru](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/merlindru/32/32096_2.png) [@merlindru](https://forums.swift.org/u/merlindru)\
**Post date:** [October 12, 2023, 3:55pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/3 "2023-10-12T15:55:26Z")

</div>

Thanks! It seems to be stuck on this for 3s:

```swift
debug: /usr/bin/xcrun --sdk xros --show-sdk-platform-path

```

Do you maybe have any idea what could be causing this?

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [October 12, 2023, 4:02pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/4 "2023-10-12T16:02:28Z")

</div>

I'm not familiar with it. The command runs fine on my system. The general approach to investigate issues like this is using process tracing tool. You can try `dtruss` if you're interested.

---

<div class="post-metadata">

**Author:** ![merlindru](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/merlindru/32/32096_2.png) [@merlindru](https://forums.swift.org/u/merlindru)\
**Post date:** [October 12, 2023, 4:13pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/5 "2023-10-12T16:13:33Z")

</div>

Thank you :) I really appreciate your help

---

<div class="post-metadata">

**Author:** ![Farial](https://avatars.discourse-cdn.com/v4/letter/f/3bc359/32.png) [@Farial](https://forums.swift.org/u/Farial)\
**Post date:** [October 12, 2023, 4:26pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/6 "2023-10-12T16:26:46Z")

</div>

Hello, the specific reason seems to be unknown. I suggest that you ensure your versions are the latest to get optimized performance.

You may check the Swift version with: **swift --version**

---

<div class="post-metadata">

**Author:** ![merlindru](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/merlindru/32/32096_2.png) [@merlindru](https://forums.swift.org/u/merlindru)\
**Post date:** [October 12, 2023, 4:57pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/7 "2023-10-12T16:57:15Z")

</div>

I'm on 5.9:

```swift
$ swift --version
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0

```

---

<div class="post-metadata">

**Author:** ![tokizo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tokizo/32/32119_2.png) [@tokizo](https://forums.swift.org/u/tokizo)\
**Post date:** [October 14, 2023, 12:00pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/8 "2023-10-14T12:00:05Z")

</div>

Same for me, it's taking about 3 seconds and it's slow. Swift 5.9.

---

<div class="post-metadata">

**Author:** ![mickeyl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mickeyl/32/12258_2.png) [@mickeyl](https://forums.swift.org/u/mickeyl)\
**Post date:** [October 16, 2023, 8:26am UTC](https://forums.swift.org/t/swift-run-really-slow/67807/9 "2023-10-16T08:26:27Z")

</div>

> [@merlindru](#):
>
> `/usr/bin/xcrun --sdk xros --show-sdk-platform-path`

Sounds like it's looking for VisionOS or something.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [October 16, 2023, 2:44pm UTC](https://forums.swift.org/t/swift-run-really-slow/67807/10 "2023-10-16T14:44:13Z")

</div>

Yeah, it seems like all the SDK searches are buggy and error out, at least for me. It can't even find macOS.

```swift
~ % /usr/bin/xcrun --sdk macOS --show-sdk-platform-path
2023-10-16 10:33:35.909 xcodebuild[79763:19248010] Writing error result bundle to /var/folders/c8/jdfwl8sj2f15x8vlx441smjc0000gn/T/ResultBundle_2023-16-10_10-33-0035.xcresult
xcodebuild: error: SDK "macOS" cannot be located.
2023-10-16 10:33:37.424 xcodebuild[79765:19248029] Writing error result bundle to /var/folders/c8/jdfwl8sj2f15x8vlx441smjc0000gn/T/ResultBundle_2023-16-10_10-33-0037.xcresult
xcodebuild: error: SDK "macOS" cannot be located.
xcrun: error: Failed to open property list '/Users/user/macOS/SDKSettings.plist'
2023-10-16 10:33:38.932 xcodebuild[79766:19248044] Writing error result bundle to /var/folders/c8/jdfwl8sj2f15x8vlx441smjc0000gn/T/ResultBundle_2023-16-10_10-33-0038.xcresult
xcodebuild: error: SDK "macOS" cannot be located.
xcrun: error: unable to lookup item 'PlatformPath' in SDK 'macOS'

```

---

<div class="post-metadata">

**Author:** ![Farial](https://avatars.discourse-cdn.com/v4/letter/f/3bc359/32.png) [@Farial](https://forums.swift.org/u/Farial)\
**Post date:** [October 21, 2023, 7:05am UTC](https://forums.swift.org/t/swift-run-really-slow/67807/11 "2023-10-21T07:05:52Z")

</div>

@merlindru , Your Swift version is well-updated. The reason seems to be unknown to me. I would suggest that you may trace using dtruss tool on MacOS - this may help to trace and debug.

---

<div class="post-metadata">

**Author:** ![doozMen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/doozmen/32/7803_2.png) [@doozMen](https://forums.swift.org/u/doozMen)\
**Post date:** [October 21, 2023, 7:38am UTC](https://forums.swift.org/t/swift-run-really-slow/67807/12 "2023-10-21T07:38:48Z")

</div>

I have also noticed before 5.9 swift run was really slow. As I use it in a monorepo to do some jobs in all the packages frequently but the code does not change often I decided to diff the folder and on changes I run `swift run` normally and without changes `swift run --skip-build` this increases the speed but still nog compared to running the executable directly.

I would like swift run to do

1. diff for me to see if it should rebuild
2. run the executable

It seams to do a lot more and I cannot see why it does that. Thanks for investigating why that is! I will do the same.

Could we file a here? [apple/swift-package-manager: The Package Manager for the Swift Programming Language](https://github.com/apple/swift-package-manager)

---

<div class="post-metadata">

**Author:** ![tokizo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tokizo/32/32119_2.png) [@tokizo](https://forums.swift.org/u/tokizo)\
**Post date:** [November 5, 2023, 1:54am UTC](https://forums.swift.org/t/swift-run-really-slow/67807/13 "2023-11-05T01:54:01Z")

</div>

Perhaps I found the cause. In conclusion, using regular Xcode, which is not beta, the SDK for VisionOS does not exist, so I saw that the search was taking a long time.

I ran swift run on Xcode 15 beta (Xcode 15.1, Build version 15C5042i) and it took less than 0.7 seconds.

```sh
$ time (swift run)
Building for debugging...
Build complete! (0.13s)
Hello, world!
( swift run; ) 0.04s user 0.04s system 12% cpu 0.651 total

```

I run `/usr/bin/xcrun --sdk xros --show-sdk-platform-path`, which took a long time to execute, with not beta, beta and compare the execution, the former fails and the latter succeeds.

```bash
# not beta
$ xcodebuild -version
Xcode 15.0.1
Build version 15A507
   
$ /usr/bin/xcrun --sdk xros --show-sdk-platform-path
2023-11-05 12:36:18.975 xcodebuild[23854:206385] Writing error result bundle to /var/folders/bw/c9dsq_vn3ld19lv5yf57n50m0000gn/T/ResultBundle_2023-05-11_12-36-0018.xcresult
xcodebuild: error: SDK "xros" cannot be located.
2023-11-05 12:36:20.426 xcodebuild[23855:206411] Writing error result bundle to /var/folders/bw/c9dsq_vn3ld19lv5yf57n50m0000gn/T/ResultBundle_2023-05-11_12-36-0020.xcresult
xcodebuild: error: SDK "xros" cannot be located.
xcrun: error: unable to lookup item 'PlatformPath' in SDK 'xros'

# beta
$ xcodebuild -version
Xcode 15.1
Build version 15C5042i
   
$ /usr/bin/xcrun --sdk xros --show-sdk-platform-path
/Applications/Xcode-beta2_15_1.app/Contents/Developer/Platforms/XROS.platform

```
