-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks!
Seems safe to me, and it's great if it speeds things up so much, but could you please add a few comments? I'm afraid it's not as obvious for us as it is for you :)
...t/src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusClassFileLocator.java
Outdated
Show resolved
Hide resolved
...src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.java
Outdated
Show resolved
Hide resolved
...rm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java
Outdated
Show resolved
Hide resolved
Updated to add the suggested comments; also now registering the Panache super types as "core types" so they'd also benefit from caching, if used. |
Note to self: this implies that if we have live-reload tests in Panache which have entities using the same package name as Panache itself they might fail now for the silly reason of us skipping the work on such classes. |
...rm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateEntityEnhancer.java
Outdated
Show resolved
Hide resolved
c51be54
to
e1bb761
Compare
We decided to use: TODO: check this doesn't break Panache integration tests as they might be running under the same package name. |
Rebased: simplified implementation taking advantage of eb69d59 |
Ok this is ready now, it was waiting for ORM |
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.
Thanks. LGTM, just a small doubt that there might be an obsolete comment.
...t/src/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusClassFileLocator.java
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Please don't merge - I've pushed an experiment and need CI feedback. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@yrodiere I understand what's going on now, unfortunatley sharing the ByteBuddy caches would require much more work - and is tricky. So I suggest we merge this version: it shares the caches of "core types" (which we know are not being modified) but isolates the caches used for bytecode enhancement in threadlocals to ensure independent interactions. It also shared the Enhancer implementation across runs, and makes its initialization lazy. It's taking the safer approach - there's room for improvement as this forces each thread to repeat quite some work, and also allocate large structures w/o sharing those, but that would require much more work to share them safely, so I'd rather take the 80% improvement now and keep it safe until we have time to add more stricter integration tests. Ok to merge? I'd hit the button as it's already approved, but since several changes were made... |
Status for workflow
|
offtopic: @Sanne could you please take a look at this issue? It is kindof related to what you are doing here :) I tried to reproduce problem with this branch, there is still a bug. |
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.
I'm really not sure using threadlocals without ever clearing them is safe in dev mode, but I'll let you check that, and merge if you are confident.
|
||
@Override | ||
public void clear() { | ||
//not useful |
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.
You could clear the thread-local? Maybe that's not the best place to do this, but it would be nice to at least try... somewhere...
We've been bitten by classloader leaks caused by threadlocals in the past... And it can get quite bad.
final ThreadLocal<EnhancerClassLocator> localLocator = ThreadLocal | ||
.withInitial(() -> ModelTypePool.buildModelTypePool(QuarkusClassFileLocator.INSTANCE, | ||
CORE_POOL)); |
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.
This threadlocal isn't static
-- is this on purpose?
From what I can see ThreadsafeLocator
is, in practice, a singleton, so using static
here would make threadlocal cleanup easier. You know, where we restart in dev mode, drop half the classloaders but keep the same threads, resulting in threadlocals piling up...
This works far better, in my local tests.
I feel it's ready, but it will require a fix on the ORM side to be merged first:
This brings enhancement times of the large model provided as benchmark down to ~1 second, without enabling Quarkus's caching capabilities of caching enhancement of unmodified classes (which we should also enable, but it's a separate aspect)