Search code examples
iosswiftperformanceswiftui

Does SwiftUI perform any additional computation if .shadow radius is set to 0?


I'm working on optimizing few components and am introduction an optional shadow option i.e.

VStack {
 ...
}
.shadow(radius: isShadow ? 0 : 10)

The idea here is to not render shadows where they are not needed and save a bit of compute time, but I'm not sure if this use case actually achieves it.

Would appreciate a detailed explanation, maybe with references on whether performance would be a bit better with shadow of radius 0 or not. And why.


Solution

  • Please check this out:

    https://stackoverflow.com/a/74659992/22907942

    It states that you should be able to optimise your shadow drawing performance by using Shape().shadow(...) in the background layer.