Snowman
Snowman

Reputation: 32061

Why is performing an event on iOS faster the second time around?

I don't have any hardcore data supporting this, but generally, you'll notice that any app you play with or one you're working on, when the app first loads, doing something such as displaying a modal view controller is slow the first time, but every subsequent time, it's really fast. For my app, when I present a modal view controller the first time, it takes about 3 seconds, but if I do it over and over again after that, it takes less than a second every time. What is the reason for this?

Upvotes: 0

Views: 96

Answers (3)

Steven Fisher
Steven Fisher

Reputation: 44876

There's a bunch of possible explanations here.

  • Something's been cached. The first time, it had to load something from "disk," the second time it was already in memory. This could be an entire framework, or NIBs or graphic resources in the OS itself.
  • Memory management. iOS didn't have enough memory to satisfy the request the first time. iOS spent some time clearing out memory, possibly quitting background applications. The second time, it's already available.
  • Probably many others.

Upvotes: 2

Bryan
Bryan

Reputation: 12190

No, I don't notice this in my app. The cause of what you are seeing could be a hundred different things, so we need a bit more data to make an informed answer.

Suggest you run Instruments, narrow down the time window to the initial 3-second pause, then see what the machine is doing during that time. Run it multiple times and look at CPU, IO, memory, anything that could be slowing it down.

Upvotes: 2

Jim
Jim

Reputation: 73936

Caching. Off the top of my head, images are often cached, and I wouldn't be surprised if the nib was cached as well.

Upvotes: 2

Related Questions