You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2023/10/05 14:40:45 UTC

[PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

orpiske opened a new pull request, #11656:
URL: https://github.com/apache/camel/pull/11656

   In most cases, the type checks will be false, which causes the JVM to hit its slow path checking the type.
   
   This already happens subsequently, so adjust it to check only for equality at first.


-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11656:
URL: https://github.com/apache/camel/pull/11656#issuecomment-1749047860

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :robot: CI automation will test this PR automatically.
   
   :camel: Apache Camel Committers, please review the following items:
   
   * First-time contributors **require MANUAL approval** for the GitHub Actions to run
   
   * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   * You can label PRs using `build-all`, `build-dependents`, `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
   
   * Build and test logs are available in the Summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. 
   
   * :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #11656:
URL: https://github.com/apache/camel/pull/11656#discussion_r1347601292


##########
core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java:
##########
@@ -107,7 +107,7 @@ private <T> T fastConvertTo(Class<T> type, Exchange exchange, Object value) {
             return null;
         }
 
-        if (type.isInstance(value)) {
+        if (type.equals(value.getClass())) {

Review Comment:
   It's still gonna be checked for this later. This is just a duplicated one. 



-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #11656:
URL: https://github.com/apache/camel/pull/11656#issuecomment-1749048038

   Waiting for my CI tests and perf results. 


-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske merged PR #11656:
URL: https://github.com/apache/camel/pull/11656


-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on code in PR #11656:
URL: https://github.com/apache/camel/pull/11656#discussion_r1347567962


##########
core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java:
##########
@@ -107,7 +107,7 @@ private <T> T fastConvertTo(Class<T> type, Exchange exchange, Object value) {
             return null;
         }
 
-        if (type.isInstance(value)) {
+        if (type.equals(value.getClass())) {

Review Comment:
   This sounds really risky since `value` could be an instance of a subclass like in the next example:
   
   Given:
   ```
   public interface Animal {
   }
   
   public static class Dog implements Animal {
   }
   ```
   When:
   ```
   Dog pluto = new Dog();
   System.out.println("Is pluto an animal? Using isInstance " + (Animal.class.isInstance(pluto) ? "Yes" : "No"));
   System.out.println("Is pluto an animal? Using Equals " + (Animal.class.equals(pluto.getClass()) ? "Yes" : "No"));
   ```
   Then
   ```
   Is pluto an animal? Using isInstance Yes
   Is pluto an animal? Using Equals No
   ```



-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #11656:
URL: https://github.com/apache/camel/pull/11656#discussion_r1347602770


##########
core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java:
##########
@@ -107,7 +107,7 @@ private <T> T fastConvertTo(Class<T> type, Exchange exchange, Object value) {
             return null;
         }
 
-        if (type.isInstance(value)) {
+        if (type.equals(value.getClass())) {

Review Comment:
   More specifically: the code is doing this in a subsequent call, so this check runs twice. I'm just making the first check a bit lenient to avoid hitting a slow path in the JVM itself.



-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #11656:
URL: https://github.com/apache/camel/pull/11656#issuecomment-1761250609

   This one is good to go. No issues on my CI. 


-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on code in PR #11656:
URL: https://github.com/apache/camel/pull/11656#discussion_r1347567962


##########
core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java:
##########
@@ -107,7 +107,7 @@ private <T> T fastConvertTo(Class<T> type, Exchange exchange, Object value) {
             return null;
         }
 
-        if (type.isInstance(value)) {
+        if (type.equals(value.getClass())) {

Review Comment:
   This sounds really risky since `value` could be an instance of a subclass like in the next example:
   
   Given:
   ```
       public interface Animal {
       }
   
       public static class Dog implements Animal {
       }
   ```
   When:
   ```
           Dog pluto = new Dog();
           System.out.println("Is pluto an animal? Using isInstance " + (Animal.class.isInstance(pluto) ? "Yes" : "No"));
           System.out.println("Is pluto an animal? Using Equals " + (Animal.class.equals(pluto.getClass()) ? "Yes" : "No"));
   ```
   Then
   ```
   Is pluto an animal? Using isInstance Yes
   Is pluto an animal? Using Equals No
   ```



-- 
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@camel.apache.org

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


Re: [PR] (chores) camel-core: avoid hitting the JVM slow path [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #11656:
URL: https://github.com/apache/camel/pull/11656#discussion_r1347602770


##########
core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java:
##########
@@ -107,7 +107,7 @@ private <T> T fastConvertTo(Class<T> type, Exchange exchange, Object value) {
             return null;
         }
 
-        if (type.isInstance(value)) {
+        if (type.equals(value.getClass())) {

Review Comment:
   More specifically: the code is doing this check twice. I'm just making the first check a bit lenient to avoid hitting a slow path in the JVM itself.



-- 
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@camel.apache.org

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