Skip to content

Slow SpEL performance due to method sorting in ReflectiveMethodResolver #28377

Closed
@aashishin

Description

@aashishin

Hi,

I am using Spring expression language (5.3.15).

I found the following method does sorting on a list of methods (ReflectiveMethodResolver).

public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
			List<TypeDescriptor> argumentTypes) throws AccessException 

I did some benchmarking and found it cost me at least 100 milliseconds more.

Is it possible to make this sorting optional ?

I am attaching the benchmark logs with and without sorting .

Do we really need the following code ?

			// Sort methods into a sensible order
	/*		if (methods.size() > 1) {
				methods.sort((m1, m2) -> {
					 if(m1==null ||m2==null)
					 {
						 
						 System.out.println("==================Some method came null  ");
					 }
					int m1pl = m1.getParameterCount();
					int m2pl = m2.getParameterCount();
					// vararg methods go last
					if (m1pl == m2pl) {
						if (!m1.isVarArgs() && m2.isVarArgs()) {
							return -1;
						}
						else if (m1.isVarArgs() && !m2.isVarArgs()) {
							return 1;
						}
						else {
							return 0;
						}
					}
					return Integer.compare(m1pl, m2pl);
				});
			}*/

Thanks,

Aashish

translator-without-sorting.log
translatorwith-sorting-.log

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions