-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Reduce ClassUtils.forName overhead (in particular for annotation introspection purposes) [SPR-16667] #21208
Comments
Juergen Hoeller commented As mentioned in my commit comment, I'd register Feel free to extend your commit along those lines; I'll merge it right away then. |
Christoph Dreis commented Thanks. Well, actually Duration shows up as well - which I had in my initial list - but decided not to include it as it brings in java.time. I could add this as well, though - I have no strong feelings against it. What do you think? |
Juergen Hoeller commented I'd rather draw the line there and avoid any |
Juergen Hoeller commented Beyond such core classes by default, we could introduce a 'live' cache for other common classes where |
Christoph Dreis commented Sorry, I didn't manage to make the changes yesterday. but I see you closed the PR already. :( Could you point me to your commit? I can't seem to find it |
Juergen Hoeller commented
|
Juergen Hoeller commented Oh just noticed your latest comment: This is about to be committed along with a few other things. Please stay tuned for a further minute or two :-) |
Juergen Hoeller commented It's in master now, along with the extended Java language interface set. BTW, any indication where all those As for the idea of a live cache, we could pick that up separately if really needed. I have a suspicion that we might be better off fine-tuning the common callers though. |
Juergen Hoeller commented FYI, we have a hard release deadline on Tuesday, right after Easter. We're trying to wrap up all 5.0.5 work and do a final backport to 4.3.15 today. If there is anything else you'd like to raise, now is your chance for another few hours :-) |
Christoph Dreis commented Lots of the calls for the interfaces seem to come from AnnotationTypeFilter or AbstractTypeHierarchyTraversingFilter (depending on what class you think should skip the interface).
So one could argue we can skip the call already there for the well-known (annotation-less) interfaces. In fact, AnnotationTypeFilter does so already for Object.class. We could extend this to make use of a common-class cache as well. What do you think? |
Juergen Hoeller commented Interesting, so this seems to be a consequence of #16341 where we're not reading such interfaces via ASM anymore... but put some load on |
Juergen Hoeller commented That fine-tuned rule for standard Java types in |
Christoph Dreis commented I highly appreciate your efforts. Thanks. Enjoy your Easter days. |
Juergen Hoeller commented Thanks for pointing out those hotspots! Enjoy the extended weekend as well... |
Juergen Hoeller commented To wrap up this effort, I've added a similar standard Java type rule to |
Christoph Dreis commented I didn't expect that we end up optimizing my long time enemy "annotation processing" when I filed this ticket ;-). I wonder if we will hit the second condition |
Juergen Hoeller commented As for the "java" check, this is meant to kick in for Java EE annotations and also for In the meantime, I got the follow-up #21216 in the works, revising our annotatedInterfaceCache in So much for wrapping up yesterday ;-) |
Christoph Dreis opened SPR-16667 and commented
Hi,
while analyzing the calls to ClassUtils.forName() in my Spring-Boot app I noticed that there might be an opportunity to optimize some more calls of commonly known classes. E.g. when looking for calls to Java classes I saw the following distribution for a total of 13000 calls (roughly 3000 coming from Java classes):
As you notice especially Serializable and Cloneable take up a big portion here, which are missing from the common class cache. Also Enum and the Collection framework interfaces contribute to the calls.
An isolated JMH benchmark for Serializable shows the following results:
I understand that drawing the line is a difficult thing to do - in fact I had the same problem - but I'd argue we could add the Collection interfaces, Enum and Optional and the interfaces contained in the javaLanguageInterfaces field to the common class cache. That seems like a reasonable collection of commonly known classes.
I'd be happy to hear your opinion on the attached PR.
Cheers,
Christoph
Affects: 4.3.14, 5.0.4
Issue Links:
Referenced from: pull request #1761, and commits 4da27c2, 5d54adf, 22a8a66, 7a8d41e
Backported to: 4.3.15
The text was updated successfully, but these errors were encountered: