[wp-trac] [WordPress Trac] #35667: Maximum execution time error in WP_Text_Diff_Renderer_Table

WordPress Trac noreply at wordpress.org
Thu Jun 21 06:37:59 UTC 2018


#35667: Maximum execution time error in WP_Text_Diff_Renderer_Table
-------------------------------------+-----------------------------
 Reporter:  ocean90                  |       Owner:  ocean90
     Type:  defect (bug)             |      Status:  assigned
 Priority:  normal                   |   Milestone:  Future Release
Component:  Revisions                |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  needs-testing has-patch  |     Focuses:
-------------------------------------+-----------------------------

Comment (by pento):

 I've run into this on some other posts, so I did some performance work on
 it, in [attachment:35667.4.diff]:

 As has been noted on this ticket, `compute_string_distance()` is slow,
 which is caused by a combination of the `count_chars()` calls (mostly on
 very long lines), and the difference calculation, for all lines. A simple
 cache of these values reduces the total time spent in
 `compute_string_distance()` by 50%, more if there are any repeated lines
 in either of the posts.

 Using `md5()` to generate the cache keys gives us fixed length keys, which
 causes future lookups to be much faster, and memory usage to be lower,
 provided the average line length is < 32 chars.

 The second slow part is in `interleave_changed_lines()`, when adding blank
 lines for padding. `array_splice()` is a super expensive function call,
 calling it in a loop causes a significant slowdown. Instead, we can call
 it once with an array of blank lines to insert.

 Running on [attachment:revision1.txt] / [attachment:revision1.txt], it
 reduces a call to `wp_text_diff()` from 1 second to 0.1 second. It does
 cause an increase in memory usage, approximately 3MB for this test case.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/35667#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list