-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve springiness cpu usage #313
Improve springiness cpu usage #313
Conversation
Thanks @erysaj! Overall looks pretty good. My first question is about I have some plans to refactor to use a separate I've only glanced through your changes, but it looks like you simply return early if the |
I don't quite understand what early return you are talking about, and it doesn't sound correct. Could you point out in the code? |
@erysaj - I just looked through your code more and now understand what is happening. The reason the API asked for For the BubbleImages, this was just a convenient (lazy? 😢) way to package an However, as you note, this isn't the best for performance in a collection view. This PR has given me some even better ideas on how to handle this. But it needs to happen in distinct steps. Here's what I would like to do:
More info on Your Let me know your thoughts!
|
As to the topic on
I think we still need some kind of cache layer, so the same avatar can be reused between multiple cells. And I don't think that's a responsibility of this library. Personally I use UIImageView+AFNetworking, and with its bare-minimum simplicity, I don't feel the need for additional support for avatars. If that was what you're asking... |
@kenn - nice! i didn't know that category on with that, there is definitely no need to support custom back to my proposal -- it would allow caching. that would be the purpose of the
the library would ask the data source for presumably your placeholder image would be on disk (or you could use my avatar factory to create an avatar with the user's initials), and you could encapsulate downloading in your the goal here would be to make would an API like this affect your use of |
…guration" This reverts commit 3f7b5ae.
I don't like the idea of having to reload cells after image got fetched, just setting
The main thing happens in
Besides it might be convenient to have some prefixes in |
@jessesquires - in case you haven't noticed, I have reverted breaking API changes and xib modifications. You can merge for the current release |
@erysaj - thanks! i just ran your code and it looks good. 👍 i'm going to make a few changes after merging and then update the pod. |
…_cpu_usage Improve springiness cpu usage
I think the crux of this matter is how we provide a hook when image loading is finished. Right now, my [_imageView setImageWithURLRequest:request
placeholderImage:[UIImage imageNamed:@"default-avatar"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
weakImageView.image = image;
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"avatarLoaded" object:nil];
});
} failure:nil]; then, - (void)viewDidLoad
{
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAvatars) name:@"avatarLoaded" object:nil];
}
- (void)refreshAvatars
{
for (NSIndexPath *indexPath in self.collectionView.indexPathsForVisibleItems) {
Message *message = [self.messages objectAtIndex:indexPath.row];
JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
cell.avatarImageView.image = message.speaker.picture.imageView.image;
}
} I hope there is a better way... one quick idea is to expose an API to monitor a given object property change using KVO (in my case |
@kenn - thanks for all the info! very interesting. one question, what are you returning from i think this is essentially the pattern that i'm suggesting with the API change:
so the library still knows absolutely nothing about downloading, caching, etc. it is simply checking if this seems like a really good way to do this. am i missing something? |
I don't know if it's the right way, but here's my code: - (UIImageView *)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageViewForItemAtIndexPath:(NSIndexPath *)indexPath
{
Message *message = self.messages[indexPath.row];
UIImage *image = [JSQMessagesAvatarFactory avatarWithImage:message.speaker.picture.imageView.image diameter:kIconSize];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
return imageView;
} Your suggestion generally sounds good, but I don't have sufficient expertise to verify that (I'm not a full time iOS dev), and as always, the devil is in the detail, so. :) |
ok, cool. thanks @kenn ! |
@jessesquires great, thanks! Please consider the solution I suggested earlier and give users the freedom to set/update avatars in any convenient way :-) You propose to reload visible cells where you just need to update In the chat app I develop an approach similar (though it is used with table views) to the one I outlined is used and here is how it works:
|
…5_ac * commit '178e1a5ab8bcea330e63a2c760aa53e7863dd80f': (38 commits) v 5.0.4 update cocoadocs styles update cocoadocs style pod update cocoadocs.yml v 5.0.3 update library common header for new context object fix docs and formatting and minor refactoring from PR jessesquires#313. small improvements to lazily applying layout attributes to cells. close jessesquires#306. close jessesquires#281. schemes Update README.md Revert "avoid expensive view hierarchy modification during cell configuration" switch to NSParameterAssert where appropriate add userInfo dictionary to keyboard notification so that it is actually useful. jessesquires#287. avoid expensive view hierarchy modification during cell configuration do not use concurrent enumeration lazily update cell’s text view lazily update cell’s layout constraints use custom layout invalidation context to suppress unneeded computations pod update update version nums. update spec. ... Conflicts: JSQMessagesViewController/Controllers/JSQMessagesKeyboardController.m JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m
This is to address an issue #281