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 8549113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:39:03+00:00 2026-06-11T13:39:03+00:00

Consider this simple UIView subclass in an ARC-enabled iOS app that draws on the

  • 0

Consider this simple UIView subclass in an ARC-enabled iOS app that draws on the view when the screen is touched:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint location = [[touches anyObject] locationInView:self];

    int padding = brushSize / 2;

    CGRect brushRect = CGRectMake(
        location.x - padding, location.y - padding,
        brushSize, brushSize
    );

    [self setNeedsDisplayInRect:brushRect];

}

- (void)drawRect:(CGRect)rect {

    NSDate *start = [NSDate date];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, rect, brushImage);

    NSLog(@"%f", [start timeIntervalSinceNow]);

}

In this example, brushImage is a square bitmap, and brushSize is an int describing the width and height of the bitmap.

I consistently get log output like this:

-0.131658
-0.133998
-0.143314
-0.007132
-0.006968
-0.007444
-0.006733
-0.008574
-0.007163
-0.006560
-0.006958

The first calls to drawRect take much longer to complete than subsequent calls, and drawRect continues to be consistently fast thereafter. It’s only on the first calls after the view is initialized that drawRect is slow.

I see similar results in both the simulator and all physical devices I’ve tried. The initial calls always take much longer to complete.

Why is drawRect / CGContextDrawImage so slow on the initial calls? And more importantly, how can I fix this?

  • 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-06-11T13:39:04+00:00Added an answer on June 11, 2026 at 1:39 pm

    Check the rect. I bet the first three are fullscreen updates. I ran into this issue before. IOS will forcibly update the first few times as fullscreen no matter what you do (probably for its GL buffering system). If you leave it alone for about 5 seconds, and then draw something again you will get the same behavior. I never figured out what the actual cause was, and I doubt I ever will :(.

    See the question I originally asked: UIGraphicsGetCurrentContext() short lifetime

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

Sidebar

Related Questions

consider this simple and pointless code. #include <iostream> struct A { template<int N> void
Consider this simple class that demonstrates RAII in C++ (From the top of my
consider this simple servlet sample: protected void doGet(HttpServletRequest request, HttpServletResponse response){ Cookie cookie =
Consider this simple model: A base Location table: +-------------------------------+ | Locations | +-------------------------------+ |(PK)
consider this simple function def foo(l=[]): if not l: print List is empty else
Consider this simple example - public class Person { private String name; private Date
Consider this simple AS3 class. package { import flash.display.Sprite; import flash.display.MovieClip; public class MySprite
Consider this simple XML document. The serialized XML shown here is the result of
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays

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.