commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-340) performance problem with EqualsBuilder.append()
Date Sun, 06 Sep 2009 23:37:57 GMT

    [ https://issues.apache.org/jira/browse/LANG-340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12751976#action_12751976
] 

Henri Yandell commented on LANG-340:
------------------------------------

LANG-526 is a general performance improvement suggestion ticket.

> performance problem with EqualsBuilder.append()
> -----------------------------------------------
>
>                 Key: LANG-340
>                 URL: https://issues.apache.org/jira/browse/LANG-340
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>            Reporter: Ramil Israfilov
>             Fix For: 3.0
>
>
> We are using EqualsBuilder for construction of equals() method in our javabeans.
> For example we have a class:
> public class SimpleRecord{
> String name;
> String label;
> ...
>     public boolean equals(Object object) {
>         return new EqualsBuilder().append(this.label, rhs.label).append(
>                 this.getName(), rhs.getName()).isEquals();
>     }
> So far so good.
> But one of our applications uses extensively Stack to push/pop SimpleRecord bean. And
it was working very slow.
> After profiling of application we saw that most of the time JVM spent in equals() method
of SimpleRecord. (it is called during peek() which is calling remove() from Stack)
> If we replace EqualsBuilder by following code our application worked 3 times faster !
Could you make some optimizations ?
>     	if (!(object instanceof SimpleRecord)) {
>             return false;
>         }
>         SimpleRecord rhs = (SimpleRecord) object;
>         if (this.getName() == null && rhs.getName() != null) {
>         	return false;
>         } else 
>         if (rhs.getName() == null && this.getName() != null) {
>         	return false;
>         } else
>         if (this.label == null && rhs.label != null) {
>         	return false;
>         } else
>         if (rhs.label == null && this.label != null) {
>         	return false;
>         } else
>         if (this.label == null && rhs.label == null) {
>         	return this.getName().equals(rhs.getName()); 
>         } else
>         
>         return this.getName().equals(rhs.getName()) && this.label.equals(rhs.label);

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message