Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-9126

Enable StringBundler to do reflection String creation

    Details

    • Branch Version/s:
      5.2.x, 5.1.x
    • Backported to Branch:
      Committed

      Description

      String's immutable property is crucial for Java security, however there is no free lunch, the safety comes with performance overhead.

      All String's public constructors do copy protection which may cause massive garbage creation. Most JDKs provide a package level String constructor which allows creating mutable String for performance. But since String is final and java.lang package is protected by a secure classloader, we can not access it by normal ways.

      This fix will enable StringBundler to use reflection to access this package level constructor, which means we are creating a mutable String, but its mutable property is limited within StringBundler.toString(), and we guarantee StringBundler won't do anything wrong, so this won't cause any security hole. (Your code can still extends and overwrite StringBundler, or even uses reflection to hack into StringBundler to do bad things, there is no way to stop you from that, but at least this is not worse than String itself).

      Since some JDK impls may not have this package level constructor, so StringBundler will do a look up first. If this constructor is absent, it will do a normal String creation.

      There is a debate for this improvement, although saving garbage can improve performance, reflection invoking will slow us down. So we should not do reflection creation all the time.
      I give StringBundler a threshold, only Strings bigger than that will be created by reflection invoking. It is your duty to set it to a reasonable number to make sure this is actually improving performance, not harming it. By my benchmark experience, a good number maybe >= 32768(32K), well this is just a suggestion, you'd better tune this number against your own system. The number here is for char, depends on your coding and content, the actually byte size may be different.

      For your safety, i turn this feature off(set threshold to 0) by default. Try to turn it on and tune it, if you have massive GC problem.

      In our MessageBoard benchmark test case, by turn on this and set it to 32768(32K), we save 6.9% young gen collections and 9.5% old gen collections.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                9 years, 51 weeks, 4 days ago

                Packages

                Version Package
                6.0.1 RC
                6.0.2 RC