twitter-kit-android icon indicating copy to clipboard operation
twitter-kit-android copied to clipboard

Initial loading of Tweet really slow

Open Sammekl opened this issue 6 years ago • 2 comments

Loading a Tweet for the first time takes around 20 seconds. After that it's loaded really quickly. This behaviour only appears when running the app. When attaching a debugger, there is no issue.

We have a view which has to show 4 tweets. The following code is used to retrieve a tweet:

fun setupTweetView(tweetId: Long) {
        Log.d("TwitterTweetView", "Load tweet")
        TweetUtils.loadTweet(tweetId, object: Callback<Tweet>() {
            override fun success(result: Result<Tweet>?) {
                Log.d("TwitterTweetView", "Retrieved tweet: ${result?.data?.id}")
                ...
            }

            override fun failure(exception: TwitterException?) {
                ...
            }
        })
}

Which has the following output in Logcat:

02-09 15:47:05.818 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Load tweet
02-09 15:47:25.981 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Load tweet
02-09 15:47:25.983 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Load tweet
02-09 15:47:25.985 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Load tweet
02-09 15:47:27.410 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Retrieved tweet: 949225619698651137
02-09 15:47:27.546 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Retrieved tweet: 949248745069318145
02-09 15:47:27.568 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Retrieved tweet: 949232444867317760
02-09 15:47:27.586 28189-28189/com.sammekl.mytwitterapp D/TwitterTweetView: Retrieved tweet: 949240163661643776

Notice the time between the first and second call! No callback is triggered yet. This appears to happen on various Android devices, emulators and SDK versions.

According to the changelog this issue was fixed in 3.2.0, but I still encounter this issue.

Sammekl avatar Feb 09 '18 14:02 Sammekl

I do too. I've been trying to integrate twitter today, with the main problem being this incredible delay for the first loaded tweet. I will be pulling twitter support from my app. It's absolutely absurd that this library takes 10 seconds to load a TWEET.

By contrast I'm using Glide to pull in images inline, and it works so much better.

ghost avatar Feb 21 '18 14:02 ghost

I've introduced a workaround in my Application onCreate() method:

For Kotlin: Thread { TweetUi.getInstance()}.start()

For Java: new Thread(TweetUi::getInstance).start();

This will make sure that the TweetUi is loaded on app start

Sammekl avatar Feb 28 '18 13:02 Sammekl