[ 
https://issues.apache.org/jira/browse/LANG-1830?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved LANG-1830.
-----------------------------------
    Fix Version/s: 3.21.0
       Resolution: Fixed

[~kzhun]The PR has been merged, please verify and close.

> Avoid repeated regex compilation in ClassUtils.toCleanName()
> ------------------------------------------------------------
>
>                 Key: LANG-1830
>                 URL: https://issues.apache.org/jira/browse/LANG-1830
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Maksym Korshun
>            Priority: Minor
>             Fix For: 3.21.0
>
>
> ClassUtils.toCleanName() currently validates the array suffix using 
> String.matches(), 
> which recompiles the regular expression on every call.
> Replace the repeated call to String.matches("(?:
> [])+") 
> with a private static final Pattern and reuse it for validation.
> This reduces unnecessary regex compilation in a frequently used utility 
> method without changing behavior.
>  
> A simple JMH benchmark comparing the current implementation with a 
> precompiled {{Pattern}} showed approximately 4x-9x higher throughput, 
> depending on the input.
>  
> ||Benchmark||Score (ops/s)||
> |ClassUtilsRegexBenchmark.precompiledPattern|32800762.230|
> |ClassUtilsRegexBenchmark.precompiledPattern|25525841.466|
> |ClassUtilsRegexBenchmark.precompiledPattern|59534277.654|
> |ClassUtilsRegexBenchmark.stringMatches|6529300.056|
> |ClassUtilsRegexBenchmark.stringMatches|5999979.754|
> |ClassUtilsRegexBenchmark.stringMatches|7142911.032|
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to