Skip to content

Optimize ClassUtils#getMostSpecificMethod #30272

@dreis2211

Description

@dreis2211

Hi,

I've been profiling some (test-)application context starts lately on Spring Framework 5.x and noticed that with one of our medium-larger applications - which I'm unfortunately not able to share - that during startup almost 100K exceptions are being thrown (caused by some Aspects not in our control). The large majority of this is ending up in ClassUtils.getMostSpecificMethod. The majority of cases seems to be caused by checking for the static factory methods on Map.of, Map.ofEntriesetc. with the target class Properties where we already now that they won't exist. (Properties is checked because Spring Data repositories have an inner bean for the named queries, I believe)

image

I can't imagine this to be super fast or efficient. Could we do anything about that? I'm wondering if it would make sense to exclude static methods here in the first place. Or have some sort of pre-defined list of methods or classes that we know won't find certain things. Or caching the lookups etc.

We haven't been able to upgrade these apps so far to 6.x because the Spring-Security changes are blocking us from a smoother upgrade, but a quick check also revealed that nothing really drastically changed in that regards in the codebase and the risk of checking for methods that are known to not exist still applies. Having that said, there might be a chance that this particular issue for us is reduced with spring-projects/spring-data-commons@712477b but I haven't been able to confirm this just yet.

Anyhow, I'd appreciate if you could take a look if this can be somehow improved.

Cheers,
Christoph

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions