Big performance hog with .removeAll ?

Discussions

Performance and scalability: Big performance hog with .removeAll ?

  1. Big performance hog with .removeAll ? (1 messages)

    Hi! We have a strange performance hog in our application, in a thread which wake up every minute. The culprit seems to be removeAll on a collection, which takes forever. This collection has about 16000 entries, and we remove nearly every entry in the operation. I demonstrate the problem with the code below. removeAll takes 15 seconds, even if a simple loop with a simple "remove" takes only 30 ms. Can "removeAll" be so broken in our case? (the lists of entries we remove and the list of entries in which we remove are nearly the same). What do you think? Thanks! Cyril import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; public class Test { private static final int NB_MAX = 16000; public static void main(String[] args) { List firstList = new ArrayList(); List secondList = new ArrayList(); List thirdList = new ArrayList(); Set theSet = new HashSet(); Set theSet2 = new HashSet(); Set theSet3 = new HashSet(); for (int i = 0; i >> secondList.removeAll(firstList): " + (new Date().getTime() - before)); before = new Date().getTime(); for (Iterator iterator = firstList.iterator(); iterator.hasNext();) { Object object = (Object) iterator.next(); thirdList.remove(object); } System.out.println(">>> thirdList.remove *" + NB_MAX + " (firstList): " + (new Date().getTime() - before)); before = new Date().getTime(); theSet.removeAll(firstList); System.out.println(">>> theSet.removeAll(firstList): " + (new Date().getTime() - before)); before = new Date().getTime(); for (Iterator iterator = firstList.iterator(); iterator.hasNext();) { Object object = (Object) iterator.next(); theSet2.remove(object); } System.out.println(">>> theSet2.remove *" + NB_MAX + " (firstList): " + (new Date().getTime() - before)); before = new Date().getTime(); if (theSet3.size() > firstList.size()) { for (Iterator i = firstList.iterator(); i.hasNext(); ) theSet3.remove(i.next()); } else { for (Iterator i = theSet3.iterator(); i.hasNext(); ) { if(firstList.contains(i.next())) { i.remove(); } } } System.out.println(">>> theSet3.removeAll handcoded(firstList): " + (new Date().getTime() - before)); } }

    Threaded Messages (1)

  2. Known bug[ Go to top ]

    Its a known bug in JDK. Refer http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6529800 ~Rajesh.B