Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DC085C151 for ; Tue, 19 Jun 2012 16:21:43 +0000 (UTC) Received: (qmail 82160 invoked by uid 500); 19 Jun 2012 16:21:43 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 82057 invoked by uid 500); 19 Jun 2012 16:21:43 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 81808 invoked by uid 99); 19 Jun 2012 16:21:43 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jun 2012 16:21:43 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id 3987A14002F for ; Tue, 19 Jun 2012 16:21:43 +0000 (UTC) Date: Tue, 19 Jun 2012 16:21:43 +0000 (UTC) From: "Thomas Neidhart (JIRA)" To: issues@commons.apache.org Message-ID: <247040161.30402.1340122903238.JavaMail.jiratomcat@issues-vm> In-Reply-To: <770527595.27527.1338573383840.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Commented] (COLLECTIONS-407) ListOrderedSet.removeAll() is slow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COLLECTIONS-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13396899#comment-13396899 ] Thomas Neidhart commented on COLLECTIONS-407: --------------------------------------------- You are right, in fact other methods (in ListOrderedSet, e.g. retainAll) already use similar logic as proposed in your patch, so I guess it is safe to do it also for the remove method. > ListOrderedSet.removeAll() is slow > ---------------------------------- > > Key: COLLECTIONS-407 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-407 > Project: Commons Collections > Issue Type: Bug > Affects Versions: 3.2.1 > Environment: java 1.6.0_24 > Ubuntu 11.10 > Reporter: Adrian Nistor > Attachments: Test.java, patch.diff > > > Hi, > I am encountering a performance problem in ListOrderedSet.removeAll(). > It appears in version 3.2.1 and also in revision 1344775 (31 May > 2012). I have attached a test that exposes this problem and a > one-line patch that fixes it. On my machine, for this test, the patch > provides a 317X speedup. > To run the test, just do: > $ java Test > The output for the un-patched version is: > Time is 3812 > The output for the patched version is: > Time is 12 > As the patch shows, the problem is in > ListOrderedSet.remove(Object object). The code for this method is: > boolean result = collection.remove(object); > setOrder.remove(object); > return result; > The patch changes it to : > boolean result = collection.remove(object); > if (result) setOrder.remove(object); > return result; > The "setOrder.remove(object)" is not necessary if > "collection.remove(object)" did not find the object. > This small change speeds up > ListOrderedSet.ListOrderedSet.removeAll(Collection coll) because > ListOrderedSet.ListOrderedSet.removeAll(Collection coll) iterates > over all the elements in "coll" and calls > ListOrderedSet.remove(Object object). So the un-patched code has > quadratic complexity, while the patched code has linear complexity. > Is this truly a bug, or am I missing something here? If so, can you > please confirm if the patch is correct? > Thanks, > Adrian -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira