Uploaded image for project: 'JSword'
  1. JSword
  2. JS-194

BibleBook EnumSet related performance issues

    Details

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

      { 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

        Attachments

          Activity

            People

            • Assignee:
              qmx Douglas Campos
              Reporter:
              mjdenham Martin Denham
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: