Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLDiff Performance inhancement #54

Merged
merged 8 commits into from
Jun 6, 2016
Merged

HTMLDiff Performance inhancement #54

merged 8 commits into from
Jun 6, 2016

Conversation

SavageTiger
Copy link
Contributor

Hi,

After the warm welcome of my last pull request I got motivated to do some more digging around in the php-htmldiff source to optimize some views in our applications that feel sluggish because of the html differ.

I made some optimizations with pretty amazing results;

  • What i did was is replaced some double operators by triple operators, narrow type comparing is way faster in PHP
  • Replaced a preg_match that checked for white space with native functions. (seems around 15% faster) depending on the amount of calls
  • Rewrote the stripTagAttributes() it created many small arrays, and then converted them back to strings, that is a pretty expensive operation.
  • The big one: created a custom version of array_slice that is called many times over in findMatch(), it caches the last request and returns the cached result when the same parameters are passed, this improved the performance dramaticly (in my test case).

There is a performance test (--group performance in phpunit). Here are my results:

(CPU: Intel(R) Core(TM) i7-3630QM CPU @ 2.40GH);

testParagraphPerformance test PHP5.6 :

v0.1.2 -> 45.75 seconds (memory: 14.50 MB)
master -> 5.93 seconds (memory: 14.50 MB)

testParagraphPerformance test PHP7 :

v0.1.2 -> 7.38 seocnds (memory: 10.0MB)
master -> 1.73 seconds (memory: 10.0MB)

The standard unit tests also feel a little faster, but since those are small its hard to measure.

@jschroed91
Copy link
Member

@SavageTiger Just glanced at this this morning, and it all looks very good 👍 I'll go through it more thoroughly a little bit later today - thank you once again for your contributions!

@jschroed91
Copy link
Member

There are also some major improvements we can do in the diffing algorithms to improve performance. We haven't created issues for them since we haven't had too many contributions up until now, but I'll be sure to create some Github issues with some explanations of improvements that can be made, in case you continue to be motivated ;)

@SavageTiger
Copy link
Contributor Author

SavageTiger commented Jun 6, 2016

Hi @jschroed9, did you find the time to look at my pull request?, If you need some clarification please let me know, happy to help.

@jschroed91
Copy link
Member

Hi @SavageTiger! Thank you for the ping :) Yes, I did look through it and it all looks great! So happy to have your contributions, feel free to keep them coming!

Merging now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants