You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "joerghoh (via GitHub)" <gi...@apache.org> on 2024/11/12 20:42:47 UTC

[PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

joerghoh opened a new pull request, #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61

   instead of trying to load the Record class all the time, just do it once and just re-use the result.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473683375

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [66.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "joerghoh (via GitHub)" <gi...@apache.org>.
joerghoh commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2472955143

   > @joerghoh - if we're doing reflection anyway, I think it would be faster to use the {{Class.getRecord}} method to check, rather than isAssignableFrom
   
   I don't think that this works on a Java11 runtime, which we still have to support.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "joerghoh (via GitHub)" <gi...@apache.org>.
joerghoh commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2476167512

   @rombert, @raducotescu @sagarmiglani many thanks for your help on this PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2472961677

   > > @joerghoh - if we're doing reflection anyway, I think it would be faster to use the {{Class.getRecord}} method to check, rather than isAssignableFrom
   > 
   > I don't think that this works on a Java11 runtime, which we still have to support.
   
   Right, but you don't have the `java.lang.Record` class on Java 11, right? What I'm saying is that you can get by reflection the "java.lang.Class.isRecord" method. If it fails, records are not supported and if it works they are.
   
   This can be done instead of the reflection-based lookup for the Record class, not in addition to.
   
   Then the "isRecord" class invokes the "java.lang.Class.isRecord" method by reflection.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473124538

   > > Right, but you don't have the java.lang.Record class on Java 11, right? What I'm saying is that you can get by reflection the "java.lang.Class.isRecord" method. If it fails, records are not supported and if it works they are.
   > 
   > I added an even simpler check - we look at the runtime version. Records are supported starting with Java 14. WDYT about relying on the JRE info?
   
   I think this can get complicated because Records are available as of Java 14 as a preview feature and delivered in 16.
   
   https://openjdk.org/jeps/395
   
   I would got for runtime detection is the `Class.isRecord` method and try to get a hold of it only once.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473096004

   > Right, but you don't have the java.lang.Record class on Java 11, right? What I'm saying is that you can get by reflection the "java.lang.Class.isRecord" method. If it fails, records are not supported and if it works they are.
   
   I added an even simpler check - we look at the runtime version. Records are supported starting with Java 14. WDYT about relying on the JRE info?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "joerghoh (via GitHub)" <gi...@apache.org>.
joerghoh commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473152950

   I also thought about finding it by checking the Java version, but that's another indirection for which I don't see any benefit.
   
   I would stick with the proposed change to actually check for the presence of ``java.lang.Record`` on class init and then proceed with the approach of the original implementation (via ``isAssignableFrom``). I think that this will mitigate the performance impact to some large extent.
   
   If you want to improve on top of that, feel free to create dedicated Jira tickets. And then we should also think about dedicated performance tests for this feature.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "joerghoh (via GitHub)" <gi...@apache.org>.
joerghoh merged PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2471554507

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [66.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473538646

   Should I remove the `JavaVersionDetector`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "sagarmiglani (via GitHub)" <gi...@apache.org>.
sagarmiglani commented on code in PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#discussion_r1839439440


##########
src/main/java/org/apache/sling/models/impl/ReflectionUtil.java:
##########
@@ -34,6 +34,18 @@
  */
 public final class ReflectionUtil {
 
+    static Class<?> recordType;
+
+    static {
+        try {
+            recordType = Class.forName("java.lang.Record");
+        } catch (ClassNotFoundException e) {
+            // this happens when running with Java11, which is supported, but
+            // of course does not have support for Record types
+            recordType = null;

Review Comment:
   IMO, It would be beneficial to include a log indicating whether Records are supported in the current setup to enhance visibility and traceability. 
   
   _Additionally nice to have would be, refactoring the supported JDK feature/classes logic into a separate class and implementing caching to minimize repeated null checks and isAssignableFrom calls during serialization, especially when handling large numbers of objects, **could be** a useful performance optimization. (but can be ignored if we are not facing significant performance degradation :) )_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "rombert (via GitHub)" <gi...@apache.org>.
rombert commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2472892484

   @joerghoh  - if we're doing reflection anyway, I think it would be faster to use the {{Class.getRecord}} method to check, rather than isAssignableFrom


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on code in PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#discussion_r1839912303


##########
src/main/java/org/apache/sling/models/impl/ReflectionUtil.java:
##########
@@ -34,6 +34,18 @@
  */
 public final class ReflectionUtil {
 
+    static Class<?> recordType;
+
+    static {
+        try {
+            recordType = Class.forName("java.lang.Record");
+        } catch (ClassNotFoundException e) {
+            // this happens when running with Java11, which is supported, but
+            // of course does not have support for Record types
+            recordType = null;

Review Comment:
   > Additionally nice to have would be, refactoring the supported JDK feature/classes logic into a separate class and implementing caching to minimize repeated null checks and isAssignableFrom calls during serialization, especially when handling large numbers of objects, could be a useful performance optimization. (but can be ignored if we are not facing significant performance degradation :) )
   
   I have started that in [0a391ba](https://github.com/apache/sling-org-apache-sling-models-impl/pull/61/commits/0a391ba113e87d62579986bc5f4a30bd37985d49).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "joerghoh (via GitHub)" <gi...@apache.org>.
joerghoh commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473545579

   > Should I remove the `JavaVersionDetector`?
   
   +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12483 load the Record class on class init [sling-org-apache-sling-models-impl]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #61:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/61#issuecomment-2473104205

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [55.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=61&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=61)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org