Skip to content

Conversation

stsypanov
Copy link
Contributor

We often use Method.getParameterTypes() which clones underlying array:

@Override
public Class<?>[] getParameterTypes() {
    return parameterTypes.clone();
}

The problem is that array is often used only to get its length, so we allocate memory mostly in vain.

Instead in numerous cases we call Method.getParameterCount introduced in Java 8:

public int getParameterCount() { return parameterTypes.length; }

which doesn't allocate.

In cases where we still need parameter types we can postpone retrieving it until it becomes inevitable.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 7, 2019
@jhoeller jhoeller self-assigned this Nov 7, 2019
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 7, 2019
@jhoeller jhoeller added this to the 5.2.2 milestone Nov 7, 2019
@jhoeller jhoeller merged commit f5ae3c7 into spring-projects:master Nov 7, 2019
@stsypanov stsypanov deleted the param-count branch November 8, 2019 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants