Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66781

QRegularExpression::match(QString...) is a performance bottleneck in multithreaded applications

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.12.0 Alpha
    • 5.9.0
    • None
    • qtdiag output attached.
      The problem is not dependent on the environment.
    • 06af9a1e3891751d89a64e9013e204176c28ebdc

    Description

       

      This is a piece of code in a function running concurrently in several threads

      static QRegularExpression maxSize("\\[(\\d+)\\]");
      QRegularExpression localMaxSize = maxSize;
      QRegularExpressionMatch maxSizeMatch = localMaxSize.match(token);
      

       

      The match function can drastically reduce parallel performances. Indeed, the QRegularExpression::match(QString...) function begins as follows:

      d.data()->compilePattern();
      
      QRegularExpressionMatchPrivate *priv = d->doMatch(subject, 0, subject.length(), offset, matchType, matchOptions);
         
      

      The compilePattern() function starts like this:

      void QRegularExpressionPrivate::compilePattern()
      {
          const QWriteLocker lock(&mutex);
      
          if (!isDirty)
              return;
          ...
      

      and the doMatch(...) does that on line 1312:

      QReadLocker lock(&mutex);
      

       

      The problem is, as far as I understand it, that compilePattern() places a write lock even when it does not need to write/compile anything (i.e. isDirty is false), preventing all other threads from placing read locks in doMatch(...).
      One of the solutions would be to move the write lock after the (!isDirty) check. Then a read lock would be needed before that check.

      If you could try to change this locking behavior, that would be great, this problem being one of the performance bottlenecks of my application.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            peppe Giuseppe D'Angelo
            xaxetrov Edern Haumont
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes