Details
-
Type: Bug
-
Status: Closed (View Workflow)
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.6.1
-
Fix Version/s: None
-
Component/s: o.c.jsword.versification
-
Labels:None
Description
The use of EnumSet to iterate over bible book enums caused a performance problem especially noticeable during startup of And Bible on low powered mobile phones.
I timed the following line in PassageKeyfactory:
whole = new ReadOnlyPassage(defaultType.createPassage("Gen 1:1-Rev 22:21"), true);
Before optimizing BibleInfo.decodeOrdinal it took 18 secs and after optimization it took 7.5 secs on a G1 mobile.
The use of
EnumSet.range(BibleBook.GEN, BibleBook.REV)
in a for loop in BibleInfo.decodeOrdinal() was extremely slow.
Here is the optimized BibleInfo.decodeOrdinal() code:
// Avoid repeated use of EnumSet by creating a List of enums
private static List<BibleBook> defaultRange;
static {
defaultRange = new ArrayList<BibleBook>();
for (BibleBook bibleBook : EnumSet.range(BibleBook.GEN, BibleBook.REV))
}
// The outer for loop in decodeOrdinal can then use the static List of enums instead of an EnumSet
for (BibleBook book: defaultRange) {
The above is a patch I will use in And Bible for now but DM will look at this in the future.
See related discussion here:
http://stackoverflow.com/questions/2464950/enum-values-vs-enumset-allof-which-one-is-more-preferable