[jsword-devel] [JIRA] Created: (JS-194) BibleBook EnumSet related performance issues

Martin Denham (JIRA) jira at crosswire.org
Sat May 28 11:27:51 MST 2011


BibleBook EnumSet related performance issues
--------------------------------------------

                 Key: JS-194
                 URL: http://www.crosswire.org/bugs/browse/JS-194
             Project: JSword
          Issue Type: Bug
          Components: o.c.jsword.versification
    Affects Versions: 1.6.1
            Reporter: Martin Denham
            Assignee: DM Smith


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)) {
            defaultRange.add(bibleBook);
        }
    }

    // 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



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jsword-devel mailing list