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

improve clean_text() performance

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.3
    • Component/s: General

      Description

      internally clean_text() uses HTMLPurifier for all html texts, we could probably skip this expensive cleaning in case of simple well formed strings...

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              skodak Petr Skoda added a comment - - edited

              Used memory on forum discussion page (macports 64 bit PHP 5.3.10):

              • before - 67MB
              • after (simple texts in forum posts, HTMLPurifier not used on page) - 60MB
              Show
              skodak Petr Skoda added a comment - - edited Used memory on forum discussion page (macports 64 bit PHP 5.3.10): before - 67MB after (simple texts in forum posts, HTMLPurifier not used on page) - 60MB
              Hide
              skodak Petr Skoda added a comment -

              Loop test:

               
              $text = "<br />abc\n<p>def<em>efg</em><strong>hi<br />j</strong></p>";
               
              $start = time();
              for ($i=0;$i<10000;$i++) {
                  purify_html($text);
              }
              echo "purifier: ".(time()-$start)." s<br />";
               
              $start = time();
              for ($i=0;$i<10000;$i++) {
                  is_purify_html_necessary($text);
              }
              echo "detection only: ".(time()-$start)." s<br />";

              Result:

              purifier: 29 s
              detection only: 0 s

              Show
              skodak Petr Skoda added a comment - Loop test:   $text = "<br />abc\n<p>def<em>efg</em><strong>hi<br />j</strong></p>";   $start = time(); for ($i=0;$i<10000;$i++) { purify_html($text); } echo "purifier: ".(time()-$start)." s<br />";   $start = time(); for ($i=0;$i<10000;$i++) { is_purify_html_necessary($text); } echo "detection only: ".(time()-$start)." s<br />"; Result: purifier: 29 s detection only: 0 s
              Hide
              samhemelryk Sam Hemelryk added a comment -

              The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

              TIA and ciao

              Show
              samhemelryk Sam Hemelryk added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
              Hide
              nebgor Aparup Banerjee added a comment -

              Hi Petr,
              this looks really cool. We should have more of these simple/quick checks for overall performance improvements i think.

              I did wonder how much does the checking add to load/time in complex/large pages with large strings ?

              I would just suggest renaming is_purify_html_necessary() to something like is_purify_html_required() or is_html_complex(since thats what the function is really checking)

              Show
              nebgor Aparup Banerjee added a comment - Hi Petr, this looks really cool. We should have more of these simple/quick checks for overall performance improvements i think. I did wonder how much does the checking add to load/time in complex/large pages with large strings ? I would just suggest renaming is_purify_html_necessary() to something like is_purify_html_required() or is_html_complex(since thats what the function is really checking)
              Hide
              skodak Petr Skoda added a comment -

              Hi,

              1/ did you see:

              if (strpos($text, '&') !== false or preg_match('|<[^pesb/]|', $text)) 

              It should kick in an vast majority of complex texts. The cost should be very tiny compared to the following htmlpurifier processing.

              2/ I guess the name is not important as long as it is grammatically correct because it is used form a single place only and is marked as @private which should exclude it from docs.

              Show
              skodak Petr Skoda added a comment - Hi, 1/ did you see: if (strpos($text, '&') !== false or preg_match('|<[^pesb/]|', $text)) It should kick in an vast majority of complex texts. The cost should be very tiny compared to the following htmlpurifier processing. 2/ I guess the name is not important as long as it is grammatically correct because it is used form a single place only and is marked as @private which should exclude it from docs.
              Hide
              skodak Petr Skoda added a comment -

              rebased + migrated tests to phpunit

              Show
              skodak Petr Skoda added a comment - rebased + migrated tests to phpunit
              Hide
              nebgor Aparup Banerjee added a comment -

              Thanks for this, its been integrated into master.

              Show
              nebgor Aparup Banerjee added a comment - Thanks for this, its been integrated into master.
              Hide
              abgreeve Adrian Greeve added a comment -

              I got no errors in the unit tests. I didn't notice any difference in speed.
              I tested this patch with a discussion that had 100 posts in it to see what the statistics were like they are as follows:

              pre-patch
              5.086309 secs RAM: 69MB RAM peak: 69.9MB
              5.719542 secs RAM: 69MB RAM peak: 69.9MB
              5.465588 secs RAM: 68.9MB RAM peak: 69.9MB
              5.34252 secs RAM: 69MB RAM peak: 69.9MB

              post-patch
              5.388531 secs RAM: 61.9MB RAM peak: 62.8MB
              4.854898 secs RAM: 61.8MB RAM peak: 62.7MB
              5.165334 secs RAM: 61.8MB RAM peak: 62.7MB
              5.124471 secs RAM: 61.8MB RAM peak: 62.7MB

              So there is a bit of improvement with the RAM.

              Show
              abgreeve Adrian Greeve added a comment - I got no errors in the unit tests. I didn't notice any difference in speed. I tested this patch with a discussion that had 100 posts in it to see what the statistics were like they are as follows: pre-patch 5.086309 secs RAM: 69MB RAM peak: 69.9MB 5.719542 secs RAM: 69MB RAM peak: 69.9MB 5.465588 secs RAM: 68.9MB RAM peak: 69.9MB 5.34252 secs RAM: 69MB RAM peak: 69.9MB post-patch 5.388531 secs RAM: 61.9MB RAM peak: 62.8MB 4.854898 secs RAM: 61.8MB RAM peak: 62.7MB 5.165334 secs RAM: 61.8MB RAM peak: 62.7MB 5.124471 secs RAM: 61.8MB RAM peak: 62.7MB So there is a bit of improvement with the RAM.
              Hide
              stronk7 Eloy Lafuente (stronk7) added a comment -

              And this has landed upstream, finally! Yay!

              תודה רבה && شكرا جزيلا



              Closing, ciao

              Show
              stronk7 Eloy Lafuente (stronk7) added a comment - And this has landed upstream, finally! Yay! תודה רבה && شكرا جزيلا Closing, ciao

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    25/Jun/12