Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling Swift with Instruments, what exactly is _swift_retain_?

I'm profiling my Swift iOS app using Instruments. A bunch of time is spent in

_swift_retain_(swift::HeapObject*) libSwiftCore.dylib

and

_swift_release_(swift::HeapObject*) libSwiftCore.dylib

My code is mostly creating (and going out of scope) structs and tuples. It's my understand that since they are value objects, they're allocated on the stack, thus I shouldn't be seeing so much heap action.

What exact does _swift_retain_ and _swift_release_ mean?

like image 604
Steve Kuo Avatar asked Jan 10 '16 01:01

Steve Kuo


1 Answers

These functions _swift_retain_ and _swift_release_ are part of Swifts automatic reference counting (ARC). For detailes, see the source in stdlib. ARC seems to be quite often nagged upon w.r.t. performance issues such as this one, but I'm surprised you see this behaviour using only value types. However, possibly this is due to something with ARC behind the hood.

like image 62
dfrib Avatar answered Oct 20 '22 17:10

dfrib