Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8059312

External party reports RegExp slowdown with case insensitivity enabled.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8u60
    • 9
    • core-libs
    • None

      From the mailing list:

      Recently I've been trying to rewrite my project to be compatible with
      Nashorn (instead of older Rhino). And I've found some interesting
      performance issues regarding regular expressions.

      It appears that object version (RegExp) with case insensitivity enabled
      performs quite bad compared to Rhino and similar variants in Nashorn (see
      the code below):

      // ------------- variant 1 - RegExp object, case insensitive search: (6.0
      sec) ------
      function srchStuff(s) {
         return RegExp('foo', 'i').exec(s);
      }
      for (i = 0; i < 5000; i += 1) {
         srchStuff('lorem ipsum dolor sit amet');
      }

      // ------ variant 2 - RegExp object, case sensitive search (0.2 sec) -----
      function srchStuff(s) {
         return RegExp('foo').exec(s);
      }
      for (i = 0; i < 5000; i += 1) {
         srchStuff('lorem ipsum dolor sit amet');
      }

      // ------ variant 3 - literal form (0.1 sec) ------------------
      function srchStuff(s) {
         return /foo/i.exec(s);
      }
      for (i = 0; i < 5000; i += 1) {
         srchStuff('lorem ipsum dolor sit amet');
      }

      // in Rhino, all the variants seem to take about the same time (~ 0.15sec)

      I know the sample represents quite a bad code as it can be easily optimized
      (pattern is static -> there is no need to instantiate RegExp again and
      again). But in a real-case scenario the 'srchStuff()' can be part of some
      external library function I need to call multiple times and then problem
      arises.

      Does anybody experienced the same problem? Or is there something I am
      missing?


      Thank you,
      Tomas

            hannesw Hannes Wallnoefer
            lagergren Marcus Lagergren
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: