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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.2.2
    • 2.2.1, 2.3
    • Libraries
    • 64bit Linux - Debian Squeeze
      Note, Debian uses glibc for iconv_substr; MacOS uses libiconv which is apparently far more efficient

      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()

            skodak Petr Skoda
            dobedobedoh Andrew Lyons
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Rajesh Taneja Rajesh Taneja
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.