Reducer switch
and SwitchStore
build times taking too long
#1183
Replies: 2 comments 5 replies
-
Hello! You can add a few build flags to get a better local view of what's taking time to build (see https://www.jessesquires.com/blog/2017/09/18/measuring-compile-times-xcode9/ for example). The app you're showing above requires you to rebuild everything from a clean slate which is quite inconvenient when iterating to improve the situation. From my experience, and for unoptimized builds, most of the time spent for compilation is caused by type checking, and you can often solve your issues by simply casting variables to help the compiler. For example, you can try to specify return types of closures if possible. Also, be wary of operators. They're usually overloaded a lot and ,IIRC, are allowed a few more levels of checks which adds up to the compilation time. The kind of issue in the line above is partly caused by them. If reducers are taking too long, you can extract some cases using functions of state and environment (technically, other reducers focused to one action only): let reducer = Reducer { state, action, environment in
switch action {
case let myAction(value):
return handleMyAction(value: value, state: &state, environment: environment)
}
}
func handleMyAction(value: Int, state: inout State, environment: Environment) -> Effect<Action, Never> {
…
} Using this approach, you should be able to spot more easily if something is taking a particularly long amount of time. I don't remember if it would present warnings for local functions you would define in the reducer, but it will surely do for top-level/first-level ones. This can be easily checked once you have a candidate that rises a warning. You can adopt the same approach with SwiftUI, and extract branches as individual views. |
Beta Was this translation helpful? Give feedback.
-
Bummer to hear about the compilation performance problems. An idea Stephen and I just sketched out is using a dedicated We wouldn't be able to release this in the library until Swift 5.7 lands, but it seems like it would work well, and allow for any number of a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Good day everyone 🖖
We introduced SCA in our current project last year and we have been growing in features using it, which led to increasing build times on it, which should be normal, but we realized when analyzing the origin of those build times, that the sources of those build times were mainly two:
switch
reducers, meaning inside there could be some huge tasks going on or just complex ones.SwitchStore
s that we currently have on the views.To give a bit more context, we are using currently
swift-composable-architecture
version0.33.1
and how the architecture looks: we have the concept of feature that 99% of the times translates to a View (with a few exceptions where there are features without a View). We have an App environment as well as local environments with specific services for those.Current build times:

Is this something already known/fixed?
If you have any suggestions questions feel free to reach out 🙏
Beta Was this translation helpful? Give feedback.
All reactions