0

The Profiler shows that CFRunLoopRun is called more than 1000 times within 20 seconds, takes up 85% and all I was doing was scrolling. The UITableView scrolling seemed laggy and I don't know what's causing the problem and calling CFRunLoopRun specifically. I have a UITableView with a custom cell that displays an image and some labels. The image is loaded on a background thread with dispatch_async(dispatch_get_global_queue,..) so I don't think that's what causing it. The imageView has rounded corners and a border, the label also have rounded corner and a background color. I'm sorry for being so unspecific but has anyone run into something similar?

Edit 1:

I looked at it again and found that the CA Render, Layout, ImageProvider takes up most of it. Here is a picture of the call tree enter image description here

Edit 2:

I've figured out that setting the imageView image calls the methods above. If I comment this one line of code where I set the image everything works fine. My question now is: why is it so slow? I've read some comments that I have to compress the image in the background first so the UIImageView doesn't have to do the job on the main thread but I couldn't come up with a good solution

Yannick
  • 3,210
  • 1
  • 21
  • 30
  • Can you show more information, like a screenshot or text of the actual stack trace? – jtbandes Mar 03 '16 at 07:59
  • Nothing in the above Profiler stack suggests any problem with `CFRunLoopRun`. All the time is eaten up in JPEG decoding. Without understanding how you've written your loading code and rendering code, I don't think we can particularly help you. It's not clear what you're talking about when you say you have to "compress the image in the background first." You haven't explained what image, why you're compressing it, or anything else. Almost certainly you're just doing way too much work in your table cell drawing; or perhaps you're spawning too many blocks. But w/o some hints, we can't really help – Rob Napier Mar 04 '16 at 03:38
  • I haven't used the profiler a lot so sorry for the wrong information. – Yannick Mar 04 '16 at 17:54

1 Answers1

0

Optimizing Image View Performance The apple docs say that the image view scales the image and that can be expensive performance-wise.

The user can save images to the database. Setting and fetching doesn't slow anything down. My problem was that the image view had to scale the images on the main thread and that cost a lost of performance. Before setting the image I have to scale it on the background thread so the image view doesn't have to do so much work. This helped me: iOS Swift: Resize image to 200x200pt/px

I hope I can save everyone who has the same prolem some time.

Community
  • 1
  • 1
Yannick
  • 3,210
  • 1
  • 21
  • 30