Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-2332

Optimize String concatenation performance

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.4
    • None

    Description

      During profiling I found that String.format provides much load on CPU.

      In many cases in Tapestry String.format can be easily replaced with simple String concatenation.

      Simple JMH (http://openjdk.java.net/projects/code-tools/jmh/) test

      public class FormatVsConcat {
          private static final String format = "This is a test string with %s";
          private static final String concat1 = "This is a test string with ";
          private static final String concat2 = "test word";
      
          @GenerateMicroBenchmark
          public String format() {
              return String.format(format, concat2);
          }
      
          @GenerateMicroBenchmark
          public String concat() {
              return concat1 + concat2;
          }
      }
      

      shows, that concatenation is 366 times faster.

      I removed only hot places in tapestry and get following results with apache benchmark:

      Not patched tapestry version:
      Requests per second: 21.38 /sec (mean)
      Time per request: 46.764 [ms] (mean)

      Patched tapestry version:
      Requests per second: 27.77 /sec (mean)
      Time per request: 36.013 [ms] (mean)

      So we gained 10ms per request or 20% of rendering time.

      If you don't mind I would like to get rid of String.format in all places of Tapestry and provide patch. I fixed only hot places which appeared during ab-profiling of one concrete page. So it is very likely that not all hot places were found and fixed.

      Attachments

        1. 0001-TAP5-2332-Replace-String.format-call-by-simple-Strin.patch
          7 kB
          Jochen Kemnade
        2. 0001-TAP5-2332-Add-a-method-for-optimized-String-concaten.patch
          12 kB
          Jochen Kemnade
        3. profile-patched.png
          199 kB
          Jochen Kemnade
        4. profile-vanilla.png
          191 kB
          Jochen Kemnade
        5. 0001-TAP5-2332-get-rid-of-String.format-usage.patch
          10 kB
          Michael Mikhulya

        Issue Links

          Activity

            People

              jkemnade Jochen Kemnade
              mihasik Michael Mikhulya
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: