[ 
https://issues.apache.org/jira/browse/CAMEL-10085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15361328#comment-15361328
 ] 

ASF GitHub Bot commented on CAMEL-10085:
----------------------------------------

GitHub user MarcinLachowicz opened a pull request:

    https://github.com/apache/camel/pull/1059

    CAMEL-10085 UnsafeUriCharactersEncoder.checkRAW...

    CAMEL-10085 UnsafeUriCharactersEncoder.checkRAW compiles regex pattern 
every call.
    
    This PR enables UnsafeUriCharactersEncoder to use static, precompiled 
pattern for checking if it matches given string. Thanks to it, performance may 
be improved. 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MarcinLachowicz/camel 
CAMEL-10085-UnsafeUriCharactersEncoder.checkRAW-compiles-regex-pattern-every-call

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/camel/pull/1059.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1059
    
----
commit 60fbb15c4cee8f04c51aed54de3dca370754dec8
Author: Marcin Lachowicz <[email protected]>
Date:   2016-07-04T12:53:34Z

    CAMEL-10085 UnsafeUriCharactersEncoder.checkRAW compiles regex pattern 
every call

----


> UnsafeUriCharactersEncoder.checkRAW compiles regex  pattern every call
> ----------------------------------------------------------------------
>
>                 Key: CAMEL-10085
>                 URL: https://issues.apache.org/jira/browse/CAMEL-10085
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.17.1
>            Reporter: Mateusz Nowakowski
>            Assignee: Andrea Cosentino
>            Priority: Minor
>             Fix For: 2.17.3, 2.18.0
>
>
> UnsafeUriCharactersEncoder.checkRAW compile regex  pattern every time it is 
> called (and it is called really often due to stack: 
> DefaultCamelContext.normalizeEndpointUri() -> URISUpport.normalizeUri() -> 
> org.apache.camel.util.UnsafeUriCharactersEncoder.encode() -> checkRaw() -> 
> Pattern.compile())
> Under high load it leads to decrease performance.
> The easiest fix is to precompile pattern:
> {code}
>     private static Pattern RAW_PATTERN = Pattern.compile("RAW\\([^\\)]+\\)");
> (....)
>     private static List<Pair> checkRAW(String s) {
>         Matcher matcher = RAW_PATTERN.matcher(s);
>         List<Pair> answer = new ArrayList<Pair>();
>         // Check all occurrences
>         while (matcher.find()) {
>             answer.add(new Pair(matcher.start(), matcher.end()));
>         }
>         return answer;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to