Skip to content

Improve PropertyMatch performance using precompiled regex patterns #3375

@kamilkrzywanski

Description

@kamilkrzywanski

Current behavior

In org.springframework.data.mapping.PropertyMatch, the matches(String name, Class<?> type) method currently uses String.matches(...):

if ((namePattern != null) && !name.matches(namePattern)) {
    return false;
}

I noticed this while profiling application startup — PropertyMatch.matches(...) is invoked repeatedly during Spring Data repository and mapping initialization, which makes the repeated regex compilation visible in startup.

Proposed improvement
Pre-compile the namePattern in the constructor of PropertyMatch as a java.util.regex.Pattern.
Change matches(...) to use Pattern.matcher(...).matches().

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions