-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Speedup Hibernate ORM's enhancement of large models #40329
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...rc/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusClassFileLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.hibernate.orm.deployment.integration; | ||
|
||
import java.io.IOException; | ||
|
||
import io.quarkus.deployment.util.IoUtil; | ||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
|
||
/** | ||
* Custom implementation of a ClassFileLocator which will load resources | ||
* from the context classloader which is set at the time of the locate() | ||
* operation is being performed. | ||
* Using a regular ForClassLoader implementation would capture the currently | ||
* set ClassLoader and keep a reference to it, while we need it to look | ||
* for a fresh copy during the enhancement. | ||
* Additionally, we might be able to optimize how the resource is actually | ||
* being loaded as we control the ClassLoader implementations | ||
* (Such further optimisations are not implemented yet). | ||
yrodiere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public final class QuarkusClassFileLocator implements ClassFileLocator { | ||
|
||
public static final QuarkusClassFileLocator INSTANCE = new QuarkusClassFileLocator(); | ||
|
||
private QuarkusClassFileLocator() { | ||
//do not invoke, use INSTANCE | ||
} | ||
|
||
@Override | ||
public Resolution locate(final String name) throws IOException { | ||
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
final byte[] bytes = IoUtil.readClassAsBytes(classLoader, name); | ||
if (bytes != null) { | ||
return new Resolution.Explicit(bytes); | ||
} else { | ||
return new Resolution.Illegal(name); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
//nothing to do | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.hibernate.orm.deployment.integration; | ||
|
||
import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; | ||
import org.hibernate.bytecode.enhance.spi.UnloadedField; | ||
|
||
public final class QuarkusEnhancementContext extends DefaultEnhancementContext { | ||
|
||
public static final QuarkusEnhancementContext INSTANCE = new QuarkusEnhancementContext(); | ||
|
||
private QuarkusEnhancementContext() { | ||
//do not invoke, use INSTANCE | ||
} | ||
|
||
@Override | ||
public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { | ||
//Don't enable automatic association management as it's often too surprising. | ||
//Also, there's several cases in which its semantics are of unspecified, | ||
//such as what should happen when dealing with ordered collections. | ||
return false; | ||
} | ||
|
||
@Override | ||
public ClassLoader getLoadingClassLoader() { | ||
//This shouldn't matter as we delegate resource location to QuarkusClassFileLocator; | ||
//make sure of this: | ||
throw new IllegalStateException("The Classloader of the EnhancementContext should not be used"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use
JAVA_V17
now? (line just below)I would create a separate PR to do it but it's going to be in your way so I will let you address it :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point :)
Amended