potential improvement for responsiveness in FBReaderJ #185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dear developers of FBReaderJ,
I'm a Ph.D. student and I'm doing research related to Android apps'
responsiveness. I found there are some cases in FBReaderJ that the
database is queried, or bitmap is generated in UI thread. Does this
affect the responsiveness of the app? An optimization could be
extracting these operations into AsyncTask.
For example, in ImageViewActivity.java, line 78 generates a bitmap
(invokes "getImageData"), which is a long computation. Is it better to
put them into a AsyncTask, so the onCreate method won't be blocked? I
attach a sample patch here. Note that there are data races on
"myBitmap" after this change, but I think the races won't lead to bugs
because you've checked if "myBitmap" is null before use it in "onDraw"
method.
Similarly, I also transformed ZLAndroidPaintContext.java,
BookInfoActivity.java, NetworkBookInfoActivity.java, since they are
also trying to get Bitmap in UI thread.
Also, in BookInfoActivity.java and LibraryActivity.java, there are
several access to IO/database in UI Thread. E.g.,
BookInfoActivity.java line 116 invokes "myBook.reloadInfoFromFile()".
This also lead to a potential responsiveness issue. Thus, I tried to
move it into AsyncTask. Similarly, LibraryActivity.java invokes
"myRootTree.Collection.saveBook" several times, which executes a
database transaction.
There should be some other places that can be improved. I can't report
all of them since I checked the code manually and it takes time. However,
what do you think about these improvements? My thought is we can improve the
responsiveness if we try to avoid the access to IO/Database, computing bitmap in
UI thread.
Thanks,
Yu