Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-413

Performance problem in DualHashBidiMap

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2.1
    • 4.0-alpha1, 4.0
    • None
    • None
    • java 1.6.0_24
      Ubuntu 11.10

    Description

      Hi,

      I am encountering a performance problem in DualHashBidiMap. It
      appears in version 3.2.1 and also in revision 1352574 (21 June 2012).
      I attached a test that exposes this problem and a patch that fixes it.
      On my machine, for this test, the patch provides a 173X speedup.

      To run the test, just do:

      $ java Test

      The output for the un-patched version is:
      Time is 5029

      The output for the patched version is:
      Time is 29

      The attached test shows that, for a "DualHashBidiMap bidi" object, the
      following operation is very slow:

      bidi.entrySet().removeAll(toRemove);

      DualHashBidiMap.entrySet() returns a
      "DualHashBidiMap.EntrySet" object, which inherits
      removeAll(Collection<?> coll) from "DualHashBidiMap.View".

      As the patch shows, the problem is that
      "DualHashBidiMap.View.removeAll(Collection<?> coll)" performs
      "coll.contains(it.next())" for each element in the View.
      "coll.contains(it.next())" can be very slow, e.g., if "coll" is a
      list.

      The patch avoids this cost by using remove(Object obj) (defined in
      "EntrySet<K, V>", "KeySet<K>", and "Values<V>"), which is fast because
      it uses only operations on sets.

      Is this a bug, or am I misunderstanding something? If so, can you
      please confirm that the patch is correct?

      Thanks,

      Adrian

      Attachments

        1. removeAll.diff
          0.8 kB
          Adrian Nistor
        2. Test.java
          0.9 kB
          Adrian Nistor

        Activity

          People

            Unassigned Unassigned
            adriannistor Adrian Nistor
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: