Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-31142

slow textlib::substr() and invalid result if length not specified

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 2.3
    • Fix Version/s: 2.2.2
    • Component/s: Libraries
    • Labels:
    • Environment:
      64bit Linux - Debian Squeeze
      Note, Debian uses glibc for iconv_substr; MacOS uses libiconv which is apparently far more efficient

      Description

      We noticed this when looking at an issue with timeouts in the rss_client block.
      The failure we were seeing was caused by the rss_client block calling lib/web.php->break_up_long_words($description, 30) where $description was a string of around 4,600 characters.
      break_up_long_words() instantiates a new textlib class and calls $textlib->substr on each character in turn; which in turn performs an iconv_substr on the supplied text.

      Effectively, the code is calling:

      $strlen = $textlib->strlen($text);
      for ($i = 0; $i < $strlen; $i++) {
        $foo += $textlib->substr($text, $i, 1);
      }

      I'll attach some code which demonstrates the performance compared with mb_string()

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              skodak Petr Skoda
              Reporter:
              dobedobedoh Andrew Nicols
              Integrator:
              Eloy Lafuente (stronk7)
              Tester:
              Rajesh Taneja
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                12/Mar/12