You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Hudson (JIRA)" <ji...@apache.org> on 2012/06/20 20:32:46 UTC

[jira] [Commented] (COLLECTIONS-410) SetUniqueList.addAll() is very slow

    [ https://issues.apache.org/jira/browse/COLLECTIONS-410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13397744#comment-13397744 ] 

Hudson commented on COLLECTIONS-410:
------------------------------------

Integrated in commons-collections #27 (See [https://builds.apache.org/job/commons-collections/27/])
    [COLLECTIONS-410] Improved performance of SetUniqueList.addAll(index, coll). Thanks to Adrian Nistor for reporting and providing a patch. (Revision 1352243)

     Result = UNSTABLE
tn : http://svn.apache.org/viewvc/?view=rev&rev=1352243
Files : 
* /commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java

                
> SetUniqueList.addAll() is very slow
> -----------------------------------
>
>                 Key: COLLECTIONS-410
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-410
>             Project: Commons Collections
>          Issue Type: Bug
>         Environment: java 1.6.0_24
> Ubuntu 11.10
>            Reporter: Adrian Nistor
>             Fix For: 4.0
>
>         Attachments: Test.java, patch.diff
>
>
> Hi,
> I am encountering a performance problem in SetUniqueList.addAll().  It
> appears in revision 1351837 (19 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 540X speedup.
> To run the test, just do:
> $ java Test
> The output for the un-patched version is:
> Time is 2706
> The output for the patched version is:
> Time is 5
> As the patch shows, the problem is that
> SetUniqueList.addAll(int index, Collection<? extends E> coll)
> performs:
> "add(index, e)" for each element in "coll". This is very expensive, 
> because each "add(index, e)" performs a 
> LinkedList.add(int index, E element), which requires traversing the 
> LinkedList to find the index.
> The patched version avoids this cost by inserting all the elements at
> once, thus performing only one insert.
> Is this a bug? If so, can you please confirm that 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