Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JpaClassUtils.isOfType performance improvement [DATAJPA-941] #1252

Closed
spring-projects-issues opened this issue Aug 2, 2016 · 0 comments
Closed
Assignees
Labels
type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 2, 2016

Milan Mimica opened DATAJPA-941 and commented

Current implementation of boolean org.springframework.data.jpa.provider.JpaClassUtils.isOfType(Object source, String typeName, ClassLoader classLoader) is slow because it's written around exception handling. Making an instance of an exception in java is quite expensive, especially before JVM optimisations kick in.
Example of a stack trace:

java.lang.Throwable.fillInStackTrace(Native Method)
java.lang.Throwable.fillInStackTrace(Throwable.java:783)
java.lang.Throwable.<init>(Throwable.java:265)
java.lang.Exception.<init>(Exception.java:66)
java.lang.RuntimeException.<init>(RuntimeException.java:62)
java.lang.ClassCastException.<init>(ClassCastException.java:58)
java.lang.Class.cast(Class.java:3369)
org.springframework.data.jpa.provider.JpaClassUtils.isOfType(JpaClassUtils.java:60)
org.springframework.data.jpa.provider.JpaClassUtils.isEntityManagerOfType(JpaClassUtils.java:46)
org.springframework.data.jpa.provider.PersistenceProvider.fromEntityManager(PersistenceProvider.java:294)
org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.createCreator(PartTreeJpaQuery.java:190)
...

The fix to simply replace it with boolean java.lang.Class.isInstance(Object obj)


Referenced from: pull request #177

Backported to: 1.10.3 (Hopper SR3), 1.9.5 (Gosling SR5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants