I have a hot loop in my code that needs to set a var to different values based on an argument (essentially using a switch statement as lookup). Because the value set is used elsewhere (and has a non-zero init time) I've created static lets for all of them. However, instruments is showing a non-trivial amount of time being spent in the member's .unsafeMutableAddressor.
How can I refactor my code to avoid this cost? It's my understanding that global variables will have the same overhead (without the scoping/namespace advantages).
pseudo code:
struct Foo {
static let matrixA = float3x3(...)
static let matrixB = float3x3(...)
@inline(__always) static func doStuff(input: SIMD3<Float>, whichToUse: SomeEnumType = .useA) -> SIMD3<Float> {
let matrix = switch whichToUse {
case .useA:
matrixA
case .useB:
matrixB
}
//...use the matrix here
}
}
'''