Podcast Search

Under the Radar

81: Profiling

Select a time to play from there. The line being spoken is highlighted as the audio plays.

0:00:00Welcome to Under the Radar, a show about independent iOS app development.

0:00:04I'm Marco Armet.

0:00:05And I'm David Smith.

0:00:06Under the Radar is never longer than 30 minutes, so let's get started.

0:00:11So as a follow-up in some ways to what we were talking about last week with debugging,

0:00:14it seemed only right to this week talk about profiling and to talk about sort of that next

0:00:20step beyond just making your app work correctly, which is largely what debugging is focused

0:00:25on, and instead to make it work in a performant way, to work not just correctly, but to work

0:00:34well as well.

0:00:35And there are some parts of profiling that are also kind of debugging and digging out

0:00:41kind of more subtle bugs, but a lot of what I've—when I turn to profiling, you know,

0:00:45when I'm in Xcode, you know, I can run, I can build and run, I can build and test,

0:00:50build and profile, build and analyze.

0:00:51Like, those are kind of the core things before I archive the build and send it off to iTunes

0:00:56Connect.

0:00:57And profiling tends to come towards the end of the process.

0:01:00And profiling generally in, you know, in this context is running Xcode, running your build

0:01:06while attached to instruments on your Mac, where instruments is this tremendously powerful

0:01:13tool that does way more things than I could possibly really understand.

0:01:18But the things that I do understand it does is just amazing, because it can give you insight

0:01:22into what is happening inside your application in a way that you can't really measure any

0:01:28other way, because it's kind of doing this—it's this interesting combination of measuring

0:01:32external things about your app, but it's doing it in a context where it is aware of

0:01:38your source code and aware of your app in a way that can give you great insight into

0:01:43what's going on.

0:01:45And there's a whole bunch of areas that we'll dive into from where profiling is

0:01:49really useful.

0:01:50But I will also mention that the one thing I always do before I go into profiling—you

0:01:54know what I mean—at the point in building an app where I hit the point where I feel

0:01:59like now I need to start tuning things down, which is largely what profiling gets into.

0:02:04Like, just earlier today, I was dealing with something with big data import, and I got

0:02:08it working correctly, but the import was taking about a minute.

0:02:11And I was like, "Mm, let me see if I can make this faster."

0:02:14And so that's when I turned to the profiler, and I work to make it faster.

0:02:19I want to make no changes to its functionality, I just want to make it faster.

0:02:22But the first thing I always do is I also, before I go into profiling, I always run build

0:02:26and analyze.

0:02:27And build and analyze in Xcode is a tool that—it's static analysis of your application.

0:02:33So it's looking for kind of structural problems or issues that you may not be aware of, like

0:02:40things where you're assigning to a value and never reading from it, or wasted work

0:02:45or structural problems.

0:02:46And I will say, it catches fewer things now than it used to for me, because I think a

0:02:51lot of this has been rolled into the compiler itself.

0:02:54And so as I'm typing out these issues, they're being lit up inside of my source editor.

0:03:01But it's still, every now and then, it will catch something that is one of these things

0:03:05that saves me a whole bunch of effort in the profiling phase, just by saying, "Hey, you're

0:03:11doing all this work and then throwing the value away without ever reading from it.

0:03:15Do you actually mean to do that?"

0:03:17So for me, I always run build and analyze first, but then I dive into the profiler.

0:03:22And that's kind of the flow that I find to work pretty well.

0:03:25Yeah, I mean, there's this whole discussion about whether you should even be optimizing

0:03:31things before it's really a problem.

0:03:33The concept of premature optimization.

0:03:36And I feel like there's, as with most things, there's a balance to be struck.

0:03:40I should have a bell for every time I say that.

0:03:43But there's a balance to be struck here.

0:03:45And the way you did it, in the example you decided was great, which is you didn't actually

0:03:51go looking for deep profiling information until there was something about your app that

0:03:56was noticeably slow.

0:03:58And that's when you decided, "Okay, I need to investigate this.

0:04:00I need to find this problem and fix it."

0:04:02That is a very healthy way to do things, as opposed to trying to micro-optimize every

0:04:10little possible step along the way, because usually if you try to do that, your code becomes

0:04:15less readable, less obvious, usually more bug-prone.

0:04:19And it's also just wasted effort a lot of the time.

0:04:21If you're going to go through and micro-optimize something, that ends up being such a tiny

0:04:26fraction of usage time that it's not even really worth having optimized.

0:04:32And so step one is try to avoid premature optimization.

0:04:36And it's arguable what counts as premature or unnecessary.

0:04:41But for the most part, if something is going to take a lot of work to make really fast,

0:04:48it's a good thing to first consider how necessary is this, and then to use the profiler to first

0:04:56profile it beforehand and see how fast or slow it is without any optimization that you

0:05:01custom do.

0:05:02And then as you try optimization methods, profile it and see, is this really helping?

0:05:08Because if it isn't, roll it back.

0:05:10Or sometimes you might think you're making something faster, or you might even be making

0:05:13it slower.

0:05:14And so you always have to not necessarily-- if you're a programmer, I feel like there's

0:05:19this instinct to make things what you think might be fast and clever and efficient and

0:05:26whatever else.

0:05:27But a lot of times, modern hardware is complicated.

0:05:30And a lot of times, things are not what you think they are in terms of relative performance.

0:05:35You might think that the more naive approach is super slow, and your clever possible optimization

0:05:42is super fast.

0:05:44But if you actually measure it with the profiler, you might find the opposite.

0:05:47You might find that, oh, it turns out the naive approach is being optimized by the compiler

0:05:52or hardware in a way that ends up making it faster than your custom optimization might

0:05:58be, or at least not substantially slower.

0:06:02There's been all sorts of optimizations over time to things like the Objective-C runtime

0:06:07and the compiler and the tools.

0:06:10And the hardware is so good now that a lot of things might seem like good candidates

0:06:15for optimization, but they actually aren't.

0:06:18And only the profiler running only on the device hardware that you're targeting can

0:06:24really tell you that a lot of the time.

0:06:26And I think, too, it's also a good point along those same lines of the importance of

0:06:30doing profiling in a quantitative approach, which is probably no surprise that that's

0:06:35what I love about profiling.

0:06:36Wow, I'm so surprised.

0:06:38But I love that you can-- and I think it's important to look at this thing from a sense

0:06:43of this operation is starting off taking this amount of time.

0:06:48Or depending on which part of the profiler you're working in, it'll be measured in

0:06:52seconds or frames per second or whatever it is.

0:06:55And having a number that you're trying to move, to affect.

0:07:01And be mindful about are you able to make substantial changes to that number.

0:07:07So in this case that I was working on this morning, I have an import that's taking

0:07:11a minute to run.

0:07:12So 60 seconds is my baseline.

0:07:14And how can I affect change to that?

0:07:18And the trap that I used to fall into a lot with profiling is feeling like I was going

0:07:25to be making progress as I was making these little improvements to that.

0:07:29Going from my 60 second target to 57 seconds by introducing some crazy convoluted scheme.

0:07:35And in theory, if you keep making these lots of small chunks into it, in theory you'll

0:07:42end up better.

0:07:43But in general, I think the thing that I've found more often is that my app is just worse

0:07:48as a result.

0:07:51When profiling works well, I'll start off with a big number, I'll find a bottleneck,

0:07:56I'll find some issue that if I can alleviate, we'll take that number and drop it in half.

0:08:02Or even better maybe.

0:08:04And if I can't find an optimization that will drop it in these big orders of magnitude

0:08:11changes, usually I just say, "That's as good as it's going to be."

0:08:14And I avoid the feeling of chasing down all these little micro-optimizations, because

0:08:21almost always they're going to reduce code readability, testability, understandability

0:08:26in the future.

0:08:27It's usually going to be something that I will regret and my future self will be very

0:08:31mad at my current self for doing.

0:08:34And it's just so much more bug prone too.

0:08:36I always have that bite me.

0:08:38Whenever I do any kind of clever optimization, it always introduces bugs that I didn't anticipate.

0:08:44And I'm working around those bugs forever from that point forward until I get rid of

0:08:49the optimization.

0:08:50Yeah.

0:08:51And so it's vitally important to make sure that if this optimization you're doing has

0:08:55a measurable and dramatic impact, like half the time, a tenth of the time, whatever it

0:09:01is, then okay, maybe this trade-off is worth doing.

0:09:04But if you aren't measuring it, you'll have no way to know the magnitude of that impact.

0:09:10Because often I'll go down there in profile, I'll be like, "Ah, I don't think I can

0:09:14make this any better."

0:09:15And that's it.

0:09:16And sometimes things are just slow in apps and that's okay.

0:09:19It's better for it to work correctly and be slow than to work fast and break because

0:09:24that's not really working at all.

0:09:27Exactly.

0:09:28And usually, I like what you said a minute ago, usually the correct number of optimizations

0:09:34to do to fix a certain problem is usually between zero and one.

0:09:39Because if, as you said, if you run a time profiler in instruments and you do the thing

0:09:46in your app that you think is slow, if there's not one big thing there that's taking up

0:09:52most of the time, it's probably not even worth doing optimization this way.

0:09:57It's probably instead, if this is a problem for your app, it's probably instead worth

0:10:00thinking like, "Okay, how can I either avoid doing this at all or how can I do it in a

0:10:05different way where it wouldn't be a problem?"

0:10:08And if you still have to do some kind of massive CPU intensive work, which I think very few

0:10:13apps do, then you look into things like, "Okay, well let me do this on a background thread

0:10:18and provide a progress UI to the user so that at least, if there's no way to make this

0:10:24fast, at least make it nice during use and make it clear what's going on."

0:10:29That's when you get into that kind of thing.

0:10:30But usually, that's not what we're dealing with in our apps.

0:10:33Usually we're dealing with more simple things.

0:10:36One example that I ran into is that in Overcast, there's this collection of podcasts and

0:10:43episodes and everything.

0:10:44And there's a lot of parts of the app that have to reload their data sources or update

0:10:50their data sources whenever the list of playable podcast episodes changes.

0:10:57This is like whenever a new episode comes in or if the user deletes or completes an

0:11:01episode or when a download completes in certain contexts where things can only be downloaded.

0:11:07So there's a few conditions here where whenever these things change, all these different parts

0:11:14of the app need to update themselves on the list of playable items for whatever reason

0:11:19that they need that list.

0:11:22This was a very, very heavy operation whenever this would happen because so many parts of

0:11:27the app need that.

0:11:28This is like the long shortcuts, the playable content manager for CarPlay, the playlist

0:11:32screen, the list of podcasts within each playlist.

0:11:36If any of these things are open and some of them are always running, like the CarPlay

0:11:38manager, you need to know when that changes.

0:11:42So whenever the playable content notification was fired, huge amounts of work had to be

0:11:48done in the app.

0:11:49This can be done in lots of apps like whenever you have a table view, reload data.

0:11:53This is a very common thing.

0:11:56Something in the data source changed, reload data.

0:11:58That's easiest most of the time than trying to do anything dynamic.

0:12:03And so it's a pretty common pattern.

0:12:05And what I was finding was that it was kind of behaving slowly.

0:12:09The app was kind of behaving slowly and people were complaining on certain phones, like the

0:12:12older ones, like the iPhone 5 or whatever else.

0:12:14So I loaded it up and I noticed on this old hardware, yeah, this is really slow.

0:12:19So I profiled it and saw it was all these table view reloads and everything from the

0:12:23playable content manager being updated.

0:12:26And so the solution here was just make that update less often.

0:12:30I was having an update on every change to the relevant tables in the database, like

0:12:37the episode table.

0:12:38Every time an episode was updated, refresh the playable content.

0:12:43But that's things like when the user listens to a few more seconds of the episode and it

0:12:47saves the progress to disk on how far they've listened.

0:12:50Well, I don't need to update it for that.

0:12:52It doesn't matter whether they've listened 30 seconds or 35 seconds in.

0:12:55So I added optimizations for things like, okay, well, don't even fire the playable content

0:13:00change notification unless certain fields have changed that actually matter.

0:13:06And I built an architecture in place for like whenever anything is listening for database

0:13:10changes in my FC model database layer class, which is open source if you want to use it,

0:13:14although I wouldn't recommend it, but if you do want to use it, go ahead.

0:13:19There's now things in there where like you can say like notify me if only these columns

0:13:24of this table change.

0:13:26And then so like I was able to build these optimizations that have pretty big impacts

0:13:30but are more in the realm of like reducing the amount of work that takes place and reducing

0:13:36the frequency of high needs operations rather than going super low level and trying to make

0:13:43like table view reloads substantially faster all over the app.

0:13:46Yeah, because I think then the big point there is it's like more often than not, the great

0:13:51thing that I find in profiling is that like the issue is something understandable.

0:13:57The optimization should likely be an obvious, tractable thing.

0:14:01Like you go through the time profiler, which is probably the one that I spend the most

0:14:04time using, and it's like, why am I calling this method 500 times?

0:14:08Oh, that's interesting.

0:14:10It's getting called 500 times a second because it's keyed into some other part of the app

0:14:15that is doing something that it really doesn't need to be communicating with it.

0:14:20It's like it's a big obvious change.

0:14:21Like, huh, that doesn't look right.

0:14:23And it's a very obvious change.

0:14:25And those are the things where if you see one of those, it's like, great, you just

0:14:28found like you can make a change that is very low risk.

0:14:31You're not kind of, it's not like, oh, no, I need to like dive into accelerate and

0:14:35do some crazy GPU version of my algorithm to avoid.

0:14:39Like, if that's what you're doing, like, that is very fun.

0:14:41I mean, that might be fun.

0:14:43That's super interesting.

0:14:44And like, see our previous episode on indulgences.

0:14:47Yeah, like, that's really cool if you if you can a do that and be if that's relevant

0:14:53to your application.

0:14:55But in the context of something like for most applications, like that's almost certainly

0:14:59not the answer.

0:15:00Like the right answer is just finding the methods that is being called too many times,

0:15:04you know, where it's like, it's your have a method that's called outside of an F where

0:15:07it should be called inside of an F, you know, it's just like, oh, you should really only

0:15:10be calling this method at the end, rather than every time you cycle through the loop

0:15:14or that kind of thing.

0:15:16And anytime you see one of those, you're like, perfect, like, like the profiler just

0:15:19saved me because it was this thing that I wouldn't see otherwise.

0:15:23Because it's hard to sometimes notice that kind of an issue.

0:15:26But when the profiler says, you call this method, you know, like, 98% of the execution

0:15:31time of your app is being called in this one method.

0:15:34You're like, huh?

0:15:36Well, that's interesting.

0:15:37And it's telling you it's giving you information that you just wouldn't know any other way.

0:15:41Yeah.

0:15:42We are sponsored this week by Linode, fast, powerful web hosting for your projects that

0:15:47you can set up in just seconds with easy to understand tools that let you choose your

0:15:51resources and your Linux distribution, giving you the power and flexibility you need.

0:15:55All this starting at just $5 a month.

0:15:58And that includes right now Linux server with one gig of RAM in the Linode cloud.

0:16:02And they're always making their deals better as hardware allows.

0:16:04It's pretty awesome being a Linode customer.

0:16:06I mean, we've been Linode customers for years now, and I cannot recommend them enough.

0:16:12They don't, they're not paying me to say this.

0:16:13They're paying me to the rest of it, but this, they cannot pay me to say.

0:16:16I love Linode.

0:16:17I use Linode and I recommend Linode.

0:16:19Anyway, back to their script.

0:16:21They have over 400,000 customers, including me and David, who are all serviced by their

0:16:24friendly 24/7 support team.

0:16:27You can email them, call them, or even chat over IRC.

0:16:29If you need help, they're there for you.

0:16:31Linode has comprehensive guides also and support documentation to teach you everything you

0:16:36need to know for setting up and managing a Linux virtual server.

0:16:39And their control panel is very nicely designed with a focus on ease of use and simplicity.

0:16:44And believe me, I've seen a lot of web hosting panels over the years.

0:16:48I've never seen one as nice as Linode.

0:16:50It's not even close.

0:16:52You can deploy, boot, resize, and clone nodes in just a few clicks.

0:16:57They have two-factor authentication.

0:16:58It is the full package for your infrastructure needs.

0:17:01So they have awesome pricing options available.

0:17:04You can get a server with one gig of RAM for just five bucks a month, as I said earlier.

0:17:07And it scales all the way up to truly ridiculous resource levels at what I consider to be the

0:17:12best values in the business.

0:17:14For example, 16 gigs of RAM for just 60 bucks a month.

0:17:17Across the board, they're offering twice the amount of RAM that you get elsewhere most

0:17:21of the time.

0:17:22So as a listener of this show, if you sign up at linode.com/radar, you'll not only be

0:17:27supporting us, but you also get $20 towards any Linode plan.

0:17:30And they have a seven-day money-back guarantee, so there's nothing to lose.

0:17:33So check out linode.com/radar.

0:17:36To learn more, sign up and take advantage of that $20 credit.

0:17:39Or you can use promo code radar2017 at checkout.

0:17:43Thank you so much to Linode, my favorite web host, for sponsoring this show and all of

0:17:48Relay FM.

0:17:49So as we wind this up, I think the place that it seems reasonable to go is to dive into

0:17:55a little bit of the actual tools within instruments that we use the most.

0:18:01And I think for me, the one that I use, like probably 90% of my profiling, is the activity

0:18:06monitor, which is an instrument that essentially, its goal is-- I mean, I'm definitely oversimplifying

0:18:13it, but essentially it counts the number of times and the amount of time spent on each

0:18:17line of code in your app while the app is running.

0:18:20I believe you're thinking of the time profiler.

0:18:22Yes.

0:18:23Does that know what I said?

0:18:24You said activity monitor.

0:18:25It's fine.

0:18:26Sure.

0:18:27Common mistake.

0:18:28The time profiler.

0:18:29You can run that one too.

0:18:30Does the activity monitor run at the same time profiler usually?

0:18:33I think so.

0:18:34I usually just use the built-in Xcode meters for general activity monitoring.

0:18:38Yeah.

0:18:39Anyway, the time profiler is a tool that I use the most often, which counts the number

0:18:45of times and the duration of the time that is spent on each line of code in your app.

0:18:49And it's a tremendously powerful tool for just finding bottlenecks, because it will

0:18:52tell you-- what I usually do is you kick that off and running, and then you sit there in

0:18:57your app.

0:18:58If it's an operation that you can do multiple times, you do it multiple times.

0:19:03Or if it's a long operation, you kick that off.

0:19:06And you can just get this great sense of where to go looking for the biggest impacts.

0:19:12Where are the biggest bottlenecks?

0:19:14And sometimes, honestly, I've even just run it-- when I'm finishing a big update, I will

0:19:18just run the time profiler and just use the app generally for five minutes, and then see

0:19:26where the biggest uses of code are.

0:19:29And sometimes you'll just discover things that you-- it's not necessarily performance

0:19:32issues, but you're like, huh, that's interesting, looking for inconsistencies or problems.

0:19:36But in general, it's just a very valuable tool to get that sense of where are the slow

0:19:42parts of my app, or where are the parts of the app where there's the biggest bottlenecks

0:19:46or the biggest use of code that is probably worth double-checking that it's as good as

0:19:50it can be.

0:19:51Right.

0:19:52And it might not even be your code.

0:19:53It might be some of Apple's code.

0:19:55But that's still useful to know, and it still might help you avoid certain unnecessary work.

0:20:00And I would also say, in general, when you're running the app, use the built-in Xcode meters

0:20:07in all parts of development.

0:20:09Whenever you run the app, use those meters.

0:20:11Just glance at it, because it'll give you an idea of what kind of CPU usage, memory

0:20:16usage, energy usage-- it'll give you an idea of what's normal for your app.

0:20:21That way, if you make a change, you notice that.

0:20:23This is the same way why I love the Mac app iStat menus, because I can tell all the time

0:20:30what my Mac's CPU usage and stuff is so I know what's normal, so I can spot easily when

0:20:35something isn't normal.

0:20:36And so it's similar here when making your apps.

0:20:39Use the metering and the tools frequently, so that way you have a baseline knowledge

0:20:43of what's OK, so when you mess something up, you'll spot it quickly.

0:20:48I would also say, in instruments-- this is a little tip for me on instruments-- for some

0:20:52reason, it's a three-paned interface, kind of like Xcode's three panes, but for some

0:20:58reason the rightmost pane is off by default, and that makes it really hard to see the value

0:21:04of things like Time Profiler.

0:21:06For a long time, I could not figure this out until I saw that that pane was off and I turned

0:21:09it on, and it will show you the line of code that is on where all the work is happening,

0:21:14but it doesn't do that if you don't turn on the third pane, so please turn the third pane

0:21:18on.

0:21:19I would also say that there's also valuable tools in the simulator.

0:21:23Besides the stuff in instruments, just in the iOS simulator, you can see a lot of potential

0:21:30issues in Performance Bottleneck, especially in rendering, in visual rendering of things.

0:21:35They have modes where they will color in the interface various tint colors or overlay colors

0:21:42for things like alpha-blended layers, which are slower to render to screen than opaque

0:21:46layers, things like misaligned views, where you might have a view on a 0.3 pixel boundary

0:21:51instead of a 1.0 or a 0.5 pixel boundary, things like that.

0:21:56They're very, very helpful in the simulator, and there's a debug menu in the simulator,

0:21:59and it's all right there, color misaligned layers or whatever.

0:22:04Use these tools, and even if you don't use them every single day, I don't think anybody

0:22:08does, but use them maybe every major version or every couple of weeks or every couple of

0:22:14months, or whenever you make a big change to the interface or to the way images are

0:22:18handled or things like that, because frame rates of your app and the resource usage of

0:22:24your app can be dramatically affected by how much blending it's doing or how much off-screen

0:22:28rendering it's having to do.

0:22:30The simulator just makes it so incredibly easy to find these things, to spot these things,

0:22:35and then to verify that you fixed them.

0:22:38Use these tools.

0:22:40I am guilty of underusing instruments, because instruments is very complicated and can be

0:22:45very intimidating, and so I really only use it to a very shallow level.

0:22:50Like David, my most commonly used one by far is Time Profiler.

0:22:54There's lots of other things it can do.

0:22:57WBC sessions are usually pretty good about it.

0:22:59If you want to learn more about it, you can look through the archive of WBC videos, because

0:23:04almost every year they do one on instruments and advanced debugging and profiling and things

0:23:07like that.

0:23:08So I highly recommend that you check those out, because there are tools here to do pretty

0:23:14remarkable things and to spot lots of possible areas for easy wins in your app.

0:23:20Like we mentioned earlier, you shouldn't go through and micro-optimize everything,

0:23:22but usually there's a couple of big things in an app that you can just make a small change

0:23:27here or there to have a really big impact.

0:23:30That's the kind of optimization that profiling is best at revealing to you, and that's what's

0:23:37the best use of your time to actually work on.

0:23:41And I think those are the kinds of things that...

0:23:43I mean, the number of times I've gone to a WBC session and I have some kind of performance

0:23:52issue, then they'll have labs where it makes sense to go and talk to somebody.

0:23:55The first thing they always do is they open up instruments and they go into the core animation

0:24:01instrument, which allows you to turn on all those cool blending color schemes for your

0:24:07app, but on device, so they'll run on your actual iPhone.

0:24:10They'll kick up the app, they'll have the time profiler running, the core animation

0:24:16instrument running with all of those different color keys turned on, and they just use the

0:24:20app and very quickly they can usually find things.

0:24:23You very quickly see, "Huh, why is the entire app...

0:24:26I can't remember what the bad color is, it's probably red."

0:24:29It's like if the whole app turns red when you're scrolling your table view, it's like,

0:24:33"Why are you doing that?

0:24:34Why do you have all of these semi-transparent things overlaid on each other?"

0:24:38You're doing all this work that you don't need to be doing.

0:24:41Or in the time profiler, similarly, they can find it.

0:24:45The core animation instrument is a great one too for just quantifying your graphical performance,

0:24:50which is really hard to do otherwise, I think, because it'll tell you the number of frames

0:24:54per second you're getting.

0:24:56Ideally, your goal is to be able to do operations at 60 frames a second, which is the maximum

0:25:02refresh rate of an iPhone.

0:25:03So if you aren't getting that, you can scroll your table view and see what your update rate

0:25:09is.

0:25:10And if it's not 60, then you're like, "Okay, now I know I have something to work with,"

0:25:13rather than just like, "It feels slow," or "It feels jerky."

0:25:17You can have these things that aren't really quite as quantifiable.

0:25:19And if it's not quantifiable, it's really hard to actually know if you're making progress

0:25:24as you're fixing things.

0:25:27We mentioned in passing a little while ago the Accelerate framework.

0:25:32This is something that a lot of developers, I don't think, know about, and most developers

0:25:36probably don't need it.

0:25:38But what this is is basically a collection of pretty low-level functions to do bulk operations

0:25:46on vectors, on a massive array of floating point numbers, or matrices, graphics operations,

0:25:54things like that.

0:25:57Most apps will never need this.

0:25:58But if--

0:25:59- I've never needed it.

0:26:00- Right.

0:26:01I only needed it when I started working with sound, because a lot of the functions of working

0:26:05with sound are made very, very nice in Accelerate.

0:26:10The VDSP section of it is kind of amazing for working with sound.

0:26:13It's designed to do that, really.

0:26:15And I would say that if your app is spending a good amount of time doing math of any sort,

0:26:23doing any kind of math operations on very large numbers of values, so if you're having

0:26:28to add, subtract, multiply 500 numbers at once for some reason, look into the Accelerate

0:26:36framework.

0:26:37It looks kind of intimidating at first.

0:26:39Again, there's good WBCC sessions on it.

0:26:41And once you figure out the crazy function naming scheme, it actually makes sense.

0:26:46So I would strongly recommend, if you're spending a meaningful amount of time on math, on large

0:26:52numbers of numbers, check out Accelerate.

0:26:55It's awesome.

0:26:56- Yeah, I've never had to dive into that myself, but that's just the nature of the apps that

0:26:59I make.

0:27:00- Yeah, I mean, again, it's one of those optimizations where you would probably never, most apps

0:27:05would probably never need it, but again, it's like if you see in Time Profile, oh, this

0:27:10one function has to compute the square root of 400 values.

0:27:14That's actually taking a noticeable amount of time, because I'm calling it so often,

0:27:17or there's so many values, and it's a processor or whatever else.

0:27:20You could fix that with one line of code that might be 10 times faster.

0:27:23- Yeah, and I guess the last profile that's probably worth mentioning is the allocations

0:27:29and leaks and memory profiling tools that you have in Xcode.

0:27:33And I mean, these have gotten incredibly sophisticated compared to what they were years ago.

0:27:39I think you can now get these dynamic memory graphs showing you your retain cycles visually,

0:27:45and it's gotten very clever, but any time, and this is, I think, what you were mentioning

0:27:51earlier, the importance of checking your little build and debug graphs just within Xcode while

0:27:57you're running, any time I see the memory footprint of my app going up over time, especially,

0:28:06you'll see it jumps up and then it stabilizes and then it jumps up again.

0:28:09It's like, uh-oh, something, I'm doing something and then never getting rid of that memory.

0:28:14And the profiler is a tremendous tool for being able to show you what you're doing wrong.

0:28:19It's like, here you're creating lots of objects and then keeping a reference to them somewhere

0:28:26that you shouldn't be or something like that.

0:28:28Usually it's, you kind of get the sense of the different shapes of your memory structure

0:28:35and you get a sense for when it's a problem and when it's not.

0:28:37'Cause sometimes you do need to use more memory and that's fine, but if you have, you see

0:28:42this constantly growing or this stepwise function that just keeps, never comes back down to

0:28:48a stable state, it's probably time to open the allocations or the leaks tool and dig

0:28:53around and see what's wrong.

0:28:55- Yeah, and all of this also, the importance of all of this grows as the amount of time

0:29:01people tend to use your app goes up.

0:29:04It's really important for me, for a podcast player, 'cause that can be running in the

0:29:07background for hours, so it really has to be stable and performance and memory have

0:29:11to be stable.

0:29:12But if you're making a utility app that somebody opens up once to convert a unit and then closes

0:29:16and won't use again for three days, it's less important and you can spend this time on things

0:29:22that are better for your business rather than micro-optimizing everything.

0:29:26Anyway, we are out of time this week, so thank you very much for listening and we'll be back

0:29:30next week with our WWDC wish list, predictions, whatever it is, whatever makes sense, we'll

0:29:34do that next week.

0:29:35So thanks everybody and we'll talk to you then.

0:29:37- Bye.

0:29:38[BLANK_AUDIO]