27

I'm using rather straightforward code to display a zoomable PDF in a scrollview, and it has been working beautifully on the iPad 2 and the original iPad. But it's staggeringly slow on the iPad 3. I know I'm pushing more pixels, but the rendering performance is simply unacceptable.

In iOS 5.0 and later, the tileSize property is arbitrarily clamped at 1024, which means tiles appear half that size on the retina display. Has anyone found a way to overcome this limitation?

Otherwise, has anyone found a way to improve the speed of the CATiledLayer on the iPad 3?

Daniel
  • 23,129
  • 12
  • 109
  • 154
dkmp
  • 367
  • 4
  • 11
  • 2
    see http://stackoverflow.com/questions/9691891/catiledlayer-in-ipad-retina-simulator-yields-poor-performance – Mat Mar 21 '12 at 09:02
  • 1
    The question Mat pointed to has a workaround for your problem. Look at all the answers as there is a better workaround for your case available, than the one present in the accepted answer. – Mihai Timar Jul 04 '12 at 17:24
  • Thanks, Mihai. Unfortunately, that link doesn't have a workaround per se; only a few tweaks. And those mostly are geared for the simulator and thus aren't of must interest for those of us developing for the device proper. For instance, one tweak suggests lowering the contentScaleFactor to 0.5, which causes the layer to render at iPad 2 (non-retina) resolution. Faster, yes, but not acceptable for a shipping product. – dkmp Jul 06 '12 at 17:54
  • Two suggestions: can you create a tiny demo project and a representative pdf file and post it on Dropbox? Also, you might want to provide a bounty as an incentive to dig. – David H Aug 10 '12 at 13:34
  • Did you remember to set the view's contentScaleFactor to 1 (or equivalently, the layer's contentScale?), ideally in -didMoveToWindow (after `[super didMoveToWindow]` sets it to whatever the current screen is)? – tc. Sep 23 '12 at 00:10

2 Answers2

1

Have you tried setting shouldRasterize to YES on the layer?

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • Well, yes - rasterizing the layer of course improves performance. But rasterization eliminates the benefit of tiled layers: the redrawing of tiles as the image is zoomed in. Rasterized tiles look terrible at any zoom level greater than 1.0. – dkmp Apr 26 '12 at 18:08
0

Did you run a time profiler on these draws and did you rule out the possibility of redundant draws?

I've had some weird double drawing, which was easily found using:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
    NSLog(@"draw %@", NSStringFromCGRect(CGContextGetClipBoundingBox(context)));
    // draw pdf
}

There's also a variety of settings to play with:

  • tiledLayer.levelsOfDetail = 2
  • tiledLayer.levelsOfDetailBias = 4
  • tiledLayer.tileSize = self.bounds.size
  • CGContextSetInterpolationQuality(context, kCGInterpolationLow)
  • CGContextSetRenderingIntent(context, kCGRenderingIntentDefault)
  • self.contentScaleFactor = 1.0
leo
  • 7,518
  • 1
  • 24
  • 25