Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16293

Improve performance of some string operations

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.13
    • Fix Version/s: 4.3.14, 5.0.3
    • Component/s: Core
    • Labels:
      None

      Description

      Hi,

      while looking into some Spring-Boot performance improvements, I noticed several opportunities to speedup String operations in the Spring-Framework as well. Mostly, but not limited to excessive substring calls.

      For the above case I did some JMH benchmarks:

      Benchmark-Code

          @Benchmark
          public String testNew(TestState testState) {
              return StringUtils.uncapitalize(testState.originalString);
          }
      
          @Benchmark
          public String testOld(TestState testState) {
      	return testState.originalString.substring(0, 1).toLowerCase() + testState.originalString.substring(1);
          }
      

      Benchmark-Results

      Benchmark.testNew                                   thrpt   10  270068983,325 ± 8686263,066   ops/s
      Benchmark.testNew:·gc.alloc.rate                    thrpt   10         ? 10??                MB/sec
      Benchmark.testNew:·gc.alloc.rate.norm               thrpt   10         ? 10??                  B/op
      Benchmark.testNew:·gc.count                         thrpt   10            ? 0                counts
      Benchmark.testOld                                   thrpt   10   15616764,260 ±  699591,770   ops/s
      Benchmark.testOld:·gc.alloc.rate                    thrpt   10       3653,894 ±     164,045  MB/sec
      Benchmark.testOld:·gc.alloc.rate.norm               thrpt   10        368,000 ±       0,001    B/op
      Benchmark.testOld:·gc.churn.PS_Eden_Space           thrpt   10       3721,582 ±     265,154  MB/sec
      Benchmark.testOld:·gc.churn.PS_Eden_Space.norm      thrpt   10        374,905 ±      24,713    B/op
      Benchmark.testOld:·gc.churn.PS_Survivor_Space       thrpt   10          0,169 ±       0,069  MB/sec
      Benchmark.testOld:·gc.churn.PS_Survivor_Space.norm  thrpt   10          0,017 ±       0,007    B/op
      Benchmark.testOld:·gc.count                         thrpt   10        151,000                counts
      Benchmark.testOld:·gc.time                          thrpt   10         80,000                    ms
      

      Please note that this shows a case, where nothing has to be done. The case in which we really have to replace something still shows an improvement-factor of 3 to 4, though.

      I hope the attached PR gets accepted and possibly merged back into 4.3.

      Cheers,
      Christoph

        Attachments

          Activity

            People

            Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            christoph.dreis Christoph Dreis
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 37 weeks, 6 days ago