Performance problems with TWTRTweetView



The problem we’re running into is the TWTRTweetView sizeThatFits method is a few orders of magnitude slower than any of our own views of equal complexity that do the same size calculations. Here’s a screenshot that profiles opening a few dozen tweets in a UICollectionView mixed in with a few dozen of our own story types:


Almost all of the time is taken up in TWTRTweetView sizeThatFits: method and on older devices like a 4S it makes the collection view unusable for almost 15 seconds. Is anyone working on TwitterKit able to take a look inside that method to see what’s going on?

As an aside it would be great if you open-sourced TwitterKit for iOS (like you’ve done with Android) so we can submit fixes.


The size calculations are definitely slow on older devices. Inside sizeThatFits: we are calling systemLayoutSizeFittingSize:UILayoutFittingCompressedSize to have the Auto Layout engine calculate the proper size for the view.


Have you tried using UICollectionViewDataSourcePrefetching? It likely won’t help for the initial load, but would certainly make subsequent loads easier.


Hi Steven, our main issue is the primary load so prefetching doesn’t really help us here. The collection view sizeForItemAtIndexPath is called to determine the height of each cell so if there are 40 tweets it’s 40 calls. On an iPhone 4S it takes close to 15 seconds with almost all of the time spent in TwitterKit’s sizeThatFits. We often have another 80 or so of our own complex cells as well that we have to calculate height for but we don’t use the autolayout engine for that simply because it’s too slow. Would be great it TwitterKit could optimize that height method (or open source it so we could do it and submit a PR like we’ve done with the Android version of TwitterKit)!