utahwithak utahwithak - 1 month ago 6
Swift Question

Removing swift_deallocClassInstance from trace

I have been attempting to optimize some Swift code and am seeing this trace:

308.00 ms 10.2% 25.00 ms swift_deallocClassInstance


I have no idea what is causing it and trying to figure out what would be dealloc-ing in the method. Has anyone seen this come up in profile or know what is causing it. It is showing up in this method. I've looked through for any sort class type vars but can't seem to pin it down. One of the methods is using some static
struct OptionSet
but those I wouldn't think would cause it. All other parameters passed are
Ints


It is over 50% of the actual method and 10% of the overall trace:

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()

}

Answer

I removed all of the option set use in the method and went directly to raw Int's and this huge hit went away. I had hoped they compiled down option sets to int or the raw value operations directly, I guess not.