从跟踪中删除 swift_deallocClassInstance

Removing swift_deallocClassInstance from trace

我一直在尝试优化一些 Swift 代码,并且看到了这个痕迹:

308.00 ms   10.2%   25.00 ms                    swift_deallocClassInstance

我不知道是什么原因造成的,也不知道该方法中会释放什么。有没有人看到过这种情况,或者知道是什么原因造成的。它出现在这种方法中。我已经查看了任何 class 类型的变量,但似乎无法确定。其中一种方法是使用一些 static struct OptionSet 但我认为不会导致它。传递的所有其他参数是 Ints

超过实际方法的50%,整体trace的10%:

final func generateTextures(options: TextureOptions, baseLevel: Int) -> [AreaData] {

    otherMethodCall();
    methodCall()

    for i in 0..<size {
        ...
    }

    for i in 0..<width {
        switch someVar {
        ...
        default:
            switch someVar {
            ...
            }
        }
    }


    for i in stride(from: width - 1, to: size, by: width) {
        switch someVar {
            ....
        default:
            switch someVar{
                ...
            }
        }
    }



    // post processing
    for i in 0..<size {
        ... method
    }

    for i in 0..<size {
        ..some more stuff
    }

    for i in 0..<size {
        ..some more stuff

    }

    anotherMethod()
    return someMethod()

}

我删除了方法中使用的所有选项集并直接转到原始 Int's,这个巨大的成功消失了。我曾希望他们直接将选项集编译为 int 或原始值操作,我猜不是。