Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8377

hashCode() generated by @EqualsAndHashCode is inefficient for instances with null fields or properties

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.12, 2.5.0-beta-2, 2.6.0-alpha-2
    • 3.0.0-alpha-1, 2.6.0-alpha-3
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              erdi Marcin Erdmann
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: