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

ASF GitHub Bot commented on GROOVY-8377:
----------------------------------------

GitHub user erdi opened a pull request:

    https://github.com/apache/groovy/pull/633

    GROOVY-8377 Equals and hash code ast performance

    See [GROOVY-8377](https://issues.apache.org/jira/browse/GROOVY-8377) for 
the rationale behind this PR.
    
    Given how simple the fix is and its impact (from 3k ops/ms to 30k ops/ms on 
my machine) I'd suggest considering backporting of it to 2.4.x, 2.5.x and 2.6.x 
lines.
    
    <rant>
    Working on this was harder then it should be down to:
    - the build takes a minute(!) to configure, I believe it is down to [this 
code](https://github.com/apache/groovy/blob/1c42f421edd91f31aa35a3e7b7113910718b35d5/build.gradle#L93)
    - the jmh benchmarks for Groovy code are broken and [needed fixing as part 
of my 
PR](https://github.com/erdi/groovy/commit/fc1d085a120bd7a542edeb7c1ff4b06816b776b2)
    
    I understand that I worked against master, but the experience was highly 
unwelcoming.
    </rant>

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/erdi/groovy 
equals-and-hash-code-ast-performance

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/633.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #633
    
----
commit fc1d085a120bd7a542edeb7c1ff4b06816b776b2
Author: Marcin Erdmann <erd...@gmail.com>
Date:   2017-11-12T10:23:26Z

    Fix Groovy dependency in performance tests to be the same as the one used 
by Gradle so that jmh benchmarks using Groovy don't fail

commit 3c6d1d462569259aad6ef95b73af4c17837595b0
Author: Marcin Erdmann <erd...@gmail.com>
Date:   2017-11-12T10:25:03Z

    Add a benchmark for hashCode() generated using @EqualsAndHashCode when 
instance on which hashCode() is called has null fields and properties

commit 2ce280083e30d912829d010592384c72b5b406cf
Author: Marcin Erdmann <erd...@gmail.com>
Date:   2017-11-12T10:26:39Z

    Add a test to verify that changes to generating hashCode() for instances 
with null fields and properties and EqualsAndHashCodeASTTransformation have no 
impact on the value returned

commit bd2b79c2cf67b99020265dca2465e18b2a40b2c8
Author: Marcin Erdmann <erd...@gmail.com>
Date:   2017-11-12T10:29:41Z

    Improve performance of generated hashCode() methods for instances with null 
fields and properties by avoiding calling NullObject.is() method for which no 
call site caching occurs.

----


> hashCode() generated by @EqualsAndHashCode is inefficient for instances with 
> null fields or properties
> ------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8377
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8377
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.12, 2.5.0-beta-2, 2.6.0-alpha-2
>            Reporter: Marcin Erdmann
>              Labels: performance
>
> In a project I work on there is a relatively large hash map for which the key 
> type has a {{@EqualsAndHashCode}} generated {{hashCode()}}. After introducing 
> an additional property to the key type, for which the value is {{null}} on 
> most instances, I noticed a massive degradation in efficiency of adds to the 
> aforementioned map.
> After some digging around it turns out that the AST generated by that 
> transform performs an identity check using {{is()}} between the 
> property/field value and {{this}}. In cases where the property/field value is 
> {{null}} this leads to a {{NullObject.is()}} call, for which, as far as I 
> understand, no call site caching occurs.
> A PR with a jmh benchmark and a very simple fix to follow.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to