title: Faster drawing of map tiles in overlays
body: <p>I'm trying to speed up the drawing of map tiles in my app, since the Time Profiler says that's where the app is running at its slowest. The project files are <a href="https://github.com/guthook/TileMapViewer/blob/master/TileMapView/TileOverlayView.m" rel="nofollow">here</a>, and the part that the Time Profiler says is slowest is this part of the drawMapRect:zoomScale:inContext method for the tile overlay--</p>
  
  <pre><code>for (ImageTile *tile in tilesInRect) {
      CGRect rect = [self rectForMapRect:tile.frame];
  
      NSString *path = tile.imagePath;
      if (path) {
          UIImage *image = [UIImage imageWithContentsOfFile:path];
  
          CGContextSaveGState(context);
          CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
  
          float scale = (overZoom/zoomScale);
  
          CGContextScaleCTM(context, scale, scale);
          CGContextTranslateCTM(context, 0, image.size.height);
          CGContextScaleCTM(context, 1, -1);
          CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), [image CGImage]);
          CGContextRestoreGState(context);
      }
  }
  </code></pre>
  
  <p>I'm guessing that using any UIImages and scaling them is what is slowing things down the most. Is there any way to speed this up, or to move the drawing to the background thread? (although doesn't drawMapRect happens in the background thread anyway, since it doesn't stop the map scrolling every time the app loads a tile)</p>