You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Christiaan <ch...@hotmail.com> on 2007/11/08 10:01:22 UTC

Performance drop in AbstractHashedMap.clear()

Hi,
I am noticing a big performance drop when executing the same method twice
within two separate transactions but with the same entitymanager involving a
large amount of objects. The method looks looks like this:

public void deleteObjects() {
   pm.currentTransaction().begin();
   Set allObjectsToDelete = new HashSet();
   collectObjectsToDelete(objectIDs, allObjectsToDelete);
   updateReferences(allObjectsToDelete);
   pm.deletePersistentAll(allObjectsToDelete);
   pm.currentTransaction().commit()
}

The allObjectsToDelete contains about 20000 objects. When executing this
method for the second time, there is a performance hit of a factor 3 to 4.
When profiling this, in the second run a new hotspot pops up in
org.apache.commons.collections.map.AbstractHashedMap.clear() This takes
413200 ms. In the first run this only takes 213 ms! (There is only 10%
increase in the number of invocations) I've included some screenshots of the
profiling data. Actually, after the first delete I notice that many methods
(like iterating a single pc collections or retrieving other fields) have
dropped in performance, I guess this is related?

kind regards,
Christiaan
-- 
View this message in context: http://www.nabble.com/Performance-drop-in-AbstractHashedMap.clear%28%29-tf4769771.html#a13643473
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Performance drop in AbstractHashedMap.clear()

Posted by Patrick Linskey <pl...@gmail.com>.
I opened OPENJPA-439 to track this.

-Patrick

On Nov 8, 2007 1:56 PM, Christiaan <ch...@hotmail.com> wrote:
>
> Hi Kevin,
> I think re-creating the Set is much faster as well. I've looked at the
> implementation of
> org.apache.commons.collections.map.AbstractHashedMap.clear() and it simply
> iterates over all entries in the hashmap and sets all references to null.
> Btw, as you can see in the backtrace (AbstractHashedMap_clear()run2.png)
> each clear is being called in BrokerImpl.endOperation(), so this would be a
> great performance improvement in the OpenJPA code.
>
> kind regards,
> Christiaan
>
> --
> View this message in context: http://www.nabble.com/Performance-drop-in-AbstractHashedMap.clear%28%29-tf4769771.html#a13656730
>
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>



-- 
Patrick Linskey
202 669 5907

Re: Performance drop in AbstractHashedMap.clear()

Posted by Christiaan <ch...@hotmail.com>.
Hi Kevin,
I think re-creating the Set is much faster as well. I've looked at the
implementation of
org.apache.commons.collections.map.AbstractHashedMap.clear() and it simply
iterates over all entries in the hashmap and sets all references to null.
Btw, as you can see in the backtrace (AbstractHashedMap_clear()run2.png)
each clear is being called in BrokerImpl.endOperation(), so this would be a
great performance improvement in the OpenJPA code.

kind regards,
Christiaan

-- 
View this message in context: http://www.nabble.com/Performance-drop-in-AbstractHashedMap.clear%28%29-tf4769771.html#a13656730
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Performance drop in AbstractHashedMap.clear()

Posted by Kevin Sutter <kw...@gmail.com>.
Christiaan,
My past experience has shown that it's much cheaper to just
delete/re-create a Collection than to call clear().  I haven't
experienced this particular scenario, but your profile data pointed at
at clear() method invocation and I wonder if that's not the problem...

Kevin

On Nov 8, 2007 3:01 AM, Christiaan <ch...@hotmail.com> wrote:
>
> Hi,
> I am noticing a big performance drop when executing the same method twice
> within two separate transactions but with the same entitymanager involving a
> large amount of objects. The method looks looks like this:
>
> public void deleteObjects() {
>    pm.currentTransaction().begin();
>    Set allObjectsToDelete = new HashSet();
>    collectObjectsToDelete(objectIDs, allObjectsToDelete);
>    updateReferences(allObjectsToDelete);
>    pm.deletePersistentAll(allObjectsToDelete);
>    pm.currentTransaction().commit()
> }
>
> The allObjectsToDelete contains about 20000 objects. When executing this
> method for the second time, there is a performance hit of a factor 3 to 4.
> When profiling this, in the second run a new hotspot pops up in
> org.apache.commons.collections.map.AbstractHashedMap.clear() This takes
> 413200 ms. In the first run this only takes 213 ms! (There is only 10%
> increase in the number of invocations) I've included some screenshots of the
> profiling data. Actually, after the first delete I notice that many methods
> (like iterating a single pc collections or retrieving other fields) have
> dropped in performance, I guess this is related?
>
> kind regards,
> Christiaan
> --
> View this message in context: http://www.nabble.com/Performance-drop-in-AbstractHashedMap.clear%28%29-tf4769771.html#a13643473
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>