Uploaded image for project: 'Tiles Autotag'
  1. Tiles Autotag
  2. AUTOTAG-24

Efficiency of regular expression under AbstractModelBody.evaluateAsString

Add voteWatch issue
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.2.0
    • None

    Description

      Despite AUTOTAG-21 the regex still eats up CPU time due to the inefficiency of the pattern s*$ which, in case of long consecutive white-space in the middle of the body, consumes O(n^2^) time while failing to match (since it will attempt to start matching at each white space position).

      Matching the actual non-whitespace content directly may be more efficient in this case, e.g

      private static final Pattern PATTERN = Pattern.compile("^\\s*+(\\S(?:.*\\S)?)\\s*$");
      
      if (body != null) {
           final Matcher matcher = PATTERN.matcher(body);
           if (matcher.matches()) {
               body = matcher.group(1);
           } else {
               body = null;
           }  
       }

      Backtracking is limited to the final white spaces, in linear time.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Hubertl Hubert Law

            Dates

              Created:
              Updated:

              Slack

                Issue deployment