Coder Social home page Coder Social logo

Comments (13)

steipete avatar steipete commented on June 8, 2024

I don't believe that's a grid issue, that's more one of your updating code. You may hook up the the scrollview to delay those changes (e.h. with using an NSOperationQueue and pausing it while scrolling) - or move more code over to a background thread. (e.g. when you "load" an image in a background thread, you don't really decompress it unless you use some arcane knowledge like this https://gist.github.com/1144242)

from gmgridview.

leberwurstsaft avatar leberwurstsaft commented on June 8, 2024

This has nothing to do with AFNetwork. With the cache I meant a RAM cache that simply keeps thumbnail images that I already loaded from flash once.

The issue seems to be that the UI updates are happening while the scrollview still scrolls, causing it to stutter.
I have offloaded everything to the background thread, preparing all the objects and loading the image.

I followed steipetes tip and further reduced the amount of work on the main thread to a minimmum. Now, the only things I actually send to the main queue are:

[label removeFromSuperview];
imgView.image = snapshot;
[cell.contentView addSubview:labelLeft];
[cell.contentView addSubview:labelRight];

When the cell is initially created I add a placeholder UIImageView and a "loading" label. Before I return the cell, I add a job to the dispatch_queue in the background, which will get the real image, and prepare the two UILabels. An on the main thread I only update the image in the UIImageView, remove the "loading" label and add two data labels.

I found that this updates the image quickly, but the labels take 1-2 seconds to show up, or sometimes don't show up at all. I wonder what's up with that. Anyway, removing the two labels alltogether made performace bearable. Still not quite what I wanted, i.e. no UI updates while scrolling.

from gmgridview.

steipete avatar steipete commented on June 8, 2024

"prepare the two UILabels" ... don't do that in the background. UIKit is totally only usable from the main thread. Not even creating UI* objects on the background is a good idea.

Have you tried my image decompression code? I totally bet this solves all your stuttering problems.

from gmgridview.

leberwurstsaft avatar leberwurstsaft commented on June 8, 2024

I see, thanks for this insight. So basically I had it more correct before - and now again, since I found the labels not showing up a bit odd.

Yes, I tried your decompression, and unfortunately it didn't help.
I made a quick video of what I'm experiencing during scrolling. It shows stuttering while scrolling slowly, and also shows how the cells get updated while inertial scrolling is going. This leads to a rather distinct hiccup once in the video.

http://vimeo.com/36936059 (password is "123", I didn't want to spam my channel)

from gmgridview.

timeuser avatar timeuser commented on June 8, 2024

I'm having a very similar experience, except the stuttering is even worse for me than what's shown in leberwurstsaft's video. I'm displaying a grid of JPG images loading using AFNetworking. There are about 12 square images on screen at once and they are retina resolution size. The really odd thing is that scrolling is very smooth on an iPhone 3GS running iOS 4.2.1, however it stutters really badly on an iPhone 4 running iOS 5.0.1?! I can mitigate it a bit using the suggestion by steipete above to suspend an operation queue while scrolling, but that seems like a really heavy and unsatisfying solution since nothing updates at all during scrolling then. I'm not sure exactly what is being discussed regarding the compression issue or how I would use that though.

from gmgridview.

steipete avatar steipete commented on June 8, 2024

very smooth on an iPhone 3GS running iOS 4.2.1, however it stutters really badly on an iPhone 4

That totally sounds like image decompression on the main thread. Did you actually try my code?

Also, firing of network calls can be expensive too... do that on a background thread.

from gmgridview.

timeuser avatar timeuser commented on June 8, 2024

I tried the decompression code. It didn't help too much. Good suggestion on the network calls, I'll try that. Thanks.

from gmgridview.

timeuser avatar timeuser commented on June 8, 2024

Turns out it was the image decompression happening on the main thread. I thought I had moved it off the main thread, but I didn't realize the success callback of AFNetworking's AFImageRequestOperation, is dispatched to the main thread and that's where I was trying to force the image decompression. Thanks steipete!

from gmgridview.

steipete avatar steipete commented on June 8, 2024

:)
I also submitted a pull request, you can now change the success and/or failure callback to any dispatch_queue you want.

from gmgridview.

timeuser avatar timeuser commented on June 8, 2024

Nice. That makes fixing it even easier. Thanks!

from gmgridview.

blackgold9 avatar blackgold9 commented on June 8, 2024

Wow. The forced decoding and success callback queue in AFNetworking made this buttery smooth.

from gmgridview.

leberwurstsaft avatar leberwurstsaft commented on June 8, 2024

Just wanted to tell that I got rid of the stuttering, the cause was mainly me using the cornerRadius and shadow* parameters of the cell views layer. Wow, what a performance monster. Now with a simple image, rendered just once, I get all the great shadows and corners I want and there is no more stuttering.

That said, steipetes preloading code is also helpful now :)

from gmgridview.

kylefox avatar kylefox commented on June 8, 2024

Wow, I've been beating my head against my desk all day trying to figure out why my images were lagging -- even though I'm loading them asynchronously from disk.

@steipete's preloading code instantly made things super smooth! Thanks!

from gmgridview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.