You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parallelize retrieving resolved packages
### Motivation:
This PR brings back the parallelization reverted
[here](#8217).
As raised in the revertal, checkouts and registry downloads mutate the
`WorkspaceState` – and running these operations in parallel can lead to
a crash since the `WorkspaceState` is not thread-safe.
### Modifications:
Based on
[this](#8217 (comment))
suggestion, I'm making `WorkspaceState` an `actor` to make access to it
thread-safe.
Additionally, I turned `ManagedDependencies` into a `struct` to ensure
its thread-safety, too. There are two methods of this struct that mutate
self – `add` and `remove`. I changed this to return a new copy of
`ManagedDependencies` instead and add counterpart methods in
`WorkspaceState` where the mutation is done in-place. Since
`ManagedDependencies` is a `Collection`, making it into an `actor`
because of two mutable methods didn't feel like the right fit. However,
let me know what you think about it.
I added comments to the key modifications to make it easier to find the
more interesting modifications since there's a lot of noise since I had
to add loads of `async` and `await`. You can find these comments below.
### Result:
[Retrieving resolved
packages](https://github.com/swiftlang/swift-package-manager/blob/0340bb12a56f9696b3966ad82c2aee1594135377/Sources/Workspace/Workspace%2BDependencies.swift#L428)
in parallel should not lead to crashes.
As suggested by @bkhouri
[here](#8217 (comment)),
I ran `WorkspaceTests` multiple times to see if I run into any
thread-safety issues:
```
for ((i=1; i<=30; i++)); do swift test --filter WorkspaceTests.WorkspaceTests; done
for ((i=1; i<=10; i++)); do swift test --filter WorkspaceTests; done
```
// rdar://86857825 do not use Dictionary(uniqueKeysWithValues:) as it can crash the process when input is incorrect such as in older versions of SwiftPM
0 commit comments