Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6977

hashCode computations generate excessive garbage objects

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 9.9.0
    • 10.0.0, 9.10.0
    • wicket-core
    • None
    • Linux, JDK18

    Description

      We observed excessive GC pressure on Wicket servers with complex component hierarchies.   Using profilers and some code inspection, we noticed an anti-pattern being used in the hashCode computations for some classes.    The slow code was first observed in AbstractJavaScriptReferenceHeaderItem, and then in related CSS classes as well.

      The common pattern in use was similar to

      int hashcode = Objects.hash(ob1, obj2, ... objn)

      which works by creating a Object[] array of size n, copying the object references into it and then calling the varargs hash() method.   In some cases, an intermediate computation was also being autoboxed, using still more memory.

      This code can be replaced with calls like

       

      int result = obj1.hashCode();
      result = 31 * result + obj2.hashCode()
      result = 31 * result + obj3.hashCode;
      return result;
      
      

      which is several times faster and does not generate any garbage objects.

      The impact is large when a containing map is resized for larger component hierarchies, resulting in repeated hashcode re-computations.

      A pull request was submitted with proposed changes to the code for this issue: link #513

       

       

       

       

      Attachments

        Issue Links

          Activity

            People

              thomas.heigl Thomas Heigl
              astange Alan Stange
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: