Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-10085

UnsafeUriCharactersEncoder.checkRAW compiles regex pattern every call

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.17.1
    • Fix Version/s: 2.17.3, 2.18.0
    • Component/s: camel-core
    • Labels:
      None
    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Novice

      Description

      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:

          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;
          }
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ancosen Andrea Cosentino
                Reporter:
                matihost Mateusz Nowakowski
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: