Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:36:15+00:00 2026-05-30T22:36:15+00:00

I am trying to execute a small piece of code on every single frame

  • 0

I am trying to execute a small piece of code on every single frame in a regular (non-OpenGL) iPhone app. The goal is to have a frame counter so that I can measure (rather than guess) where the slow points in the app are and fix them to create a better user experience.

What I’ve done so far is register a CADisplayLink for all modes (including tracking):

CADisplayLink *displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(frame)] retain];
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

The code that is executed looks like this (lastDraw is a NSDate* and count an int):

- (void) frame {
NSDate *newDate = [NSDate date];

if([newDate timeIntervalSinceDate:lastDraw] >= 1) {
    label.text = [NSString stringWithFormat:@"%d FPS", count];

    count = 0;
    [lastDraw release];
    lastDraw = [newDate retain];
}

count++;
}

The idea here is to get an update every one second as to how many frames were drawn in the past second.

This seems to work ok, but the numbers are definitely off when scrolling in a UIScrollView: If I just scroll like a normal person then the frame rates seem to make sense. However, if I scroll vigorously up and down then the displayed rate drops down to 1 or 2 fps, but clearly there are more frames drawn than just one every second.

When I change the frame method like such:

- (void) frame {
    label.text = [NSString stringWithFormat:@"%f", displayLink.timestamp];
}

It becomes obvious that very few events are fired when I scroll.

I have read a lot of articles here and around the web that deal with UIScrollViews and NSRunLoopCommonModes vs NSDefaultRunLoopMode but haven’t found someone describing my problem. The closest I found was in this question

Remember that if a CADisplayLink is unable to fire for a screen refresh (due to the main thread being busy doing things like drawing the previous frame) then it may skip it, as it won’t have enough time to complete.

I can’t seem to find any evidence for that in the official documentation, though, and hope that I am doing something wrong…

If it makes any difference the device in question is running iOS 4.3.3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:36:17+00:00Added an answer on May 30, 2026 at 10:36 pm

    I verified this with Apple in ticket #10848893 at http://bugreport.apple.com/ and it seems that indeed it is a bug that was fixed in iOS 5.1 seed 3, where I am unable to reproduce the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small bit of code that I'm trying to execute with the
I am trying to figure out a small dillema. I have a piece of
I am experimenting with compiler performance. I have a very small piece of code,
I've got a small bit of code that I'm trying to execute via an
Am trying to execute ssis package using dtexec utility from c# app(Creating New Process,
I am trying to develop a small app, that will store User's input about
I wrote a small piece of code that rapidly read and write to a
I'm trying to learn JQuery - and I have a small problem with ajax.
I've been trying to parallelize this piece of code for about two days and
I am trying to create a gui using swing. I have a main frame

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.