caxy / php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML. Includes support for comparing complex lists and tables
http://php-htmldiff.caxy.com
GNU General Public License v2.0
202 stars 51 forks source link

Issue #77: Performance Fixes #81

Closed SavageTiger closed 5 years ago

SavageTiger commented 5 years ago

Hi Josh,

After reading about all the performance troubles on the Drupal forums and in the issue https://github.com/caxy/php-htmldiff/issues/77 I thought i'd try to fix it.

Its obvious that introducing multibyte support was the big performance hit, however, it is not needed most of the time.

I realized it is pretty easy to determine if this is the case by comparing the result of strlen($text) to mb_strlen($text) and enabled / disabled mb_ functions accordingly. And this fixed the issue.

screenshot from 2019-02-13 23-07-46

I also did some small performance fixes by doing some more strict checking, and making the internal php call graph smaller. Used a profiler to fix these issues (xhprof). However the problem was that by decreasing the call-stack I think my biggest performance improvements came from the profiler having less of a hard time keeping up

jschroed91 commented 5 years ago

This is great @SavageTiger! I will take a look at this tonight or tomorrow and if all looks good will get this merged in and a new release tagged