Scrolling perfomance on iOS8
I've encountered a strange behaviour on iOS8. When I scroll the collectionView on the device with iOS8 GM, it performs with some lags, while on another device with iOS 7.1 everything is fine. Is it a well-known issue?
thanks @igrekde - no one has reported this yet. there are other GM bugs too. hopefully this will resolve itself.
@jessesquires I've tested one of the apps using your library - Parse chat and noticed the same issue.
I too experience this performance issue
Yep, I saw that too.
BTW, this problem can be seen even in the demo application.
Hey guys -- thanks for the updates!
We addressed scrolling performance issues awhile back in v5.0.3, but it looks like the issue is back. I'm not 100% sure how to resolve this, so any help is much appreciated!
Also, the release-6.0 branch now has a stable demo. I've made some changes here that should help with scrolling. It feels like it has improved to me, but it still doesn't seem as smooth as iOS 7.0.
Let me know what you think!
@jessesquires I've tested the demo app in release-6 branch, but I still experience the same perfomance issues - maybe a slightly better than in the master.
@jessesquires FYI, I just spent a couple hours trying to find where the problem is. All I can say right now is that if you comment out this line:
https://github.com/jessesquires/JSQMessagesViewController/blob/release-6.0/JSQMessagesViewController/Controllers/JSQMessagesViewController.m#L433
everything begins to run more smoothly on my iPhone5. Obviously, this is not an option :-) That said, it seems to rule out problems with rendering the bubbles or the avatars images, at least.
In my test, I simply added 50 outgoing messages in a loop to populate the conversation. The profile shows a lot of layouting activity for the UICollectionView, so my guess is simply that finding a solution for the constraint system of the cell takes too much time, which happens only when the constraints have changed (so, in my test case, when the text has changed).
Hope this helps.
I thought that this SO answer might help too, if you did not see it already: http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights#comment35309097_18746930
For the record, I just spent a few days trying to get a smooth UITableview running with cells layed out using Autolayout, and I never managed to get something satisfactory. I'm guessing that autolayout is still a bit too CPU intensive right now. Doing it "manually" in LayoutSubviews, in the other hands, did give excellent results. Just a data point.
Thanks so much for the investigation @madewulf ! Very interesting.
What makes this worse is that there are lots of optimizations already in place:
- we cache computed bubble sizes for use later
- we have a custom invalidation context
- we prevent constraint updates unless they have changed
These yielded great scrolling results under iOS 7. So something has changed with iOS 8.
Good to know that is it not the bubble or avatar images. That would have been my first guess.
I wonder if the issue is with data detectors? We should try turning them off.
I profiled the app, and it seems the issue here is the use of AutoLayout. Once everything related to auto layout is turned off, performance is suddenly very smooth.
You should consider dropping auto layout completely. There is nothing that seems difficult to layout manually, especially in cells, where you already have all the heights (or can calculate them using framework methods.
Thanks @LeoNatan !
To reiterate, this was not an issue on iOS 7. This was introduced in iOS 8. :cry:
Dropping auto-layout is not an option — with size classes and iPhone 6, it should be clear that manual layouts will not suffice. There's a reason Apple has introduced these frameworks — this is the best way to implement adaptive UI. The previous version (v4.0.x) of this library did not use auto-layout — a decision that was the source of countless bugs, limitations, and one reason why v5.0 was a complete re-write. Auto-layout is the reason why this library still "just works" on both iPhone 6 and iPhone 6 Plus in portrait and landscape. (All all other devices :smile: )
However! I think (hope) we can fix this. Don't worry, this is high-priority.
Also — everyone's comments here are a huge help! Thanks so much! Keep them coming. :+1:
I don't really see why in this case. The project is iOS7 and above, so TextKit can give you a very precise estimation of text size. For other things, the API asks the user for precise sizes. You know the container size, you know the layout size and you hear when these sizes change. All this amounts to actually quite a simple (but perhaps a little tedious) layoutSubviews. When the cell is sized correctly by the layout, performing internal layout is just as simple as pinning manually the avatar image and top and bottom to edges, and resizing the text area to fit the rest. For the bottom bar, the Auto Layout can remain, I doubt it has any real performance penalty.
I can help with this if you are interested.
@LeoNatan -- any/all help is much appreciated!
However, we should continue using auto-layout for the reasons above, but also because the 6.0 release will be finished soon. There are already significant changes in the library for 6.0 — overhauling all of the layout code is too risky this close to release.
For anyone wanting to submit a PR for this issue, please submit to branch release-6.0.
Release 6 is shaping up to be a very good release. Very cool additions.
The library is not really usable at this point. Devices such as 4S, iPad 2 and mini (non retina) really are not able to push the CPU power needed to layout the scene. I will comment only on iOS8 because I did not test on below, nor is it a consolation. With media attachments, the problem becomes even more so relevant.
In my project, I am still in a technology research phase and POC, so I don't mind the performance hit right now. But I cannot start work with this project with the current performance limitations.
If nothing comes up regarding Auto Layout performance, I will either write a lib of my own or help rewrite this one if timetable permits. Please let me know when possible.
Hello all:
After some investigation with Instruments, I've found some issues regarding scrolling performance and fixed them. Still not 100% but I think it is much better. Please pull the latest from develop and let me know how it goes.
Profiling data from Instruments Timer Profiler:
- Lots of time spent in
collectionView: cellForItemAtIndexPath:- 44.8%
dequeueReusableCellWithReuseIdentifier: forIndexPath: - 16.5%
cell.textView.text = messageText; - 30.6%
cell.cellTopLabel.attributedText = ...
- 44.8%
- Lots of time spent in
prepareForReuse/applyLayoutAttributes:- 51.4%
self.textViewFrameInsets = customAttributes.textViewFrameInsets;
- 51.4%
- Lots of time spent in
messageBubbleSizeForItemAtIndexPath:- 90.1%
boundingRectWithSize:
- 90.1%
Clearly, there are some additional areas to optimize. Right now, I'm thinking applyLayoutAttributes: could be better.
If anyone else has additional information, please report back here. :+1:
Hi, @jessesquires. I've tested the latest version of the library - it seems that the scrolling perfomance has improved a little - but it still works badly, especially with a fast scrolling. Anyway, thanks a lot for your effort. I hope, that you'll completely fix the issue.
For me on 5S it didn't improve sadly.
@LeoNatan - really? I'm testing mostly on an iPhone 5 and performance is not that bad. It's noticeably not as smooth as before, but it isn't terrible.
Hello all: a bit more progress here. Please checkout the latest on develop and let me know how this is working now.