How to avoid swift.retain/release
How to avoid swift.retain/release
- Subject: How to avoid swift.retain/release
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 09 Sep 2016 13:54:53 +0700
This code executes in a strange way: SubClass takes much longer than BaseClass.
class BaseClass
{
let hugeNumber: Int
var bitfield: UnsafeMutablePointer<UInt8>
init()
{
hugeNumber = 1_000_000_000
bitfield = calloc( hugeNumber, 1)
}
function doSomething()
{
for index = 0 to hugeNumber step 2 // pseudo code
{
self.dynamicType.setBitFieldAtIndex(index)
}
}
class function setBitFieldAtIndex( index: Int )
{
bitfield[index] = 5
}
}
final SubClass: BaseClass
{
override function doSomething()
{
for index = 0 to hugeNumber step 3 // pseudo code
{
self.dynamicType.setBitFieldAtIndex(index)
}
}
}
One assumes that SubClass is faster: it should take about 2/3 the time of BaseClass. But this is NOT the case.
Instruments Time Profiler shows (total time, % of time, self time, name of function):
BaseClass (does NOT override doSomething)
5743 ms 92.0% 644 doSomething Instruments shows only Assembly code
5099 ms 81.7% 4644 setBitFieldAtIndex
SubClass (overrides doSomething)
8407 ms 92.6% 186 doSomething Instruments can show Swift code
2693 29.6% 2576 setBitFieldAtIndex this about expected
2746 29.1% 2643 swift_retain (_swift::HeapObject) BAD
2643 29.1% 2643 swift_release (_swift::HeapObject) BAD
I guess that in BaseClass doSomething gets inlined and the compiler knows that retain/release is not needed.
So: How can I convince the compiler not to use retain/release in SubClass?
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden