Comments (13)
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.
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.
"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.
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.
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.
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.
I tried the decompression code. It didn't help too much. Good suggestion on the network calls, I'll try that. Thanks.
from gmgridview.
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.
:)
I also submitted a pull request, you can now change the success and/or failure callback to any dispatch_queue you want.
from gmgridview.
Nice. That makes fixing it even easier. Thanks!
from gmgridview.
Wow. The forced decoding and success callback queue in AFNetworking made this buttery smooth.
from gmgridview.
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.
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)
- How can items drag in both the directions Left to Right and Right to Left ?
- GMGridView reloadData does not refresh view
- Archives has does not contain a single–bundle application or contains multiple products
- iOS 7 Horizontal strategy content size HOT 2
- No document about how to use this control
- if cell width is quite different, grid will show wrong cell when rotating
- ios 5.1 and lower issue HOT 1
- Grid cell want to draw from top HOT 1
- scrollToObjectAtIndex is not working properly when paging is enabled HOT 1
- memory problem - not released/reclaimed HOT 1
- another mem issue
- GMGrid Cell Alignment Issue
- Image stuck on screen
- Sort Help required!
- gridview.edit=yes,how to use sortingdelegate?
- index = -2147483648
- Maybe you can join a group function
- Button not working in subview GMGridviewCell
- Image link in README.md is broken
- animation repeat count doesn't work in GMGridViewCell
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmgridview.