Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-12483

Improve performance of constructor-based instantiation on Java11

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Models Implementation 1.7.4
    • None
    • Sling Models
    • None

    Description

      Context:

      • Runtime with Java 11
      • Sling Models Impl 1.7.4

      When exporting a larger graph of Sling Models, the response time increased massively in comparison to Sling Models Impl 1.6.4.

      Many threaddumps look like this:

             at org.apache.sling.feature.launcher.spi.Launcher$LauncherClassLoader.loadClass(Launcher.java:50)
              - waiting to lock <0x000000059b115828> (a java.lang.Object)
              at java.lang.ClassLoader.loadClass(java.base@11.0.23/ClassLoader.java:521)
              at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1458)
              at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
              at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1976)
              at java.lang.ClassLoader.loadClass(java.base@11.0.23/ClassLoader.java:521)
              at java.lang.Class.forName0(java.base@11.0.23/Native Method)
              at java.lang.Class.forName(java.base@11.0.23/Class.java:315)
              at org.apache.sling.models.impl.ReflectionUtil.isRecord(ReflectionUtil.java:127)
              at org.apache.sling.models.impl.model.ModelClassConstructor.isCanonicalRecordConstructor(ModelClassConstructor.java:90)
              at org.apache.sling.models.impl.ModelAdapterFactory.getBestMatchingConstructor(ModelAdapterFactory.java:803)
              at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:718)
              at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:409)
              at org.apache.sling.models.impl.ModelAdapterFactory.getAdapter(ModelAdapterFactory.java:219)
              at org.apache.sling.adapter.internal.AdapterManagerImpl.getAdapter(AdapterManagerImpl.java:121)
              at org.apache.sling.models.impl.ResourceOverridingRequestWrapper.adaptTo(ResourceOverridingRequestWrapper.java:90)
              at org.apache.sling.models.impl.ModelAdapterFactory.getModelFromWrappedRequest(ModelAdapterFactory.java:1374)
              [...]
              at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341)
              at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3364)
              at org.apache.sling.models.jacksonexporter.impl.JacksonExporter.export(JacksonExporter.java:135)

      This seemed to be caused by SLING-12359, which adds support for Records. In ReflectionUtils.isRecord it constantly tries to load the class java.lang.Record which is not available in Java 11 and therefor throws a ClassNotFoundException (which is then caught to just return false)

      The locking in the classloader and the inevitable ClassNotFoundException on Java11 cause a small performance penalty, which is amplified by the Exporter, when it is serializing a large amount of models.

      Note: The Sling Model Exporter is a feature known to create Sling Models, and depending on the Sling Model graph the number can be quite large. But also other functionality is affected which is creating Sling Models.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              joerghoh Joerg Hoh
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: