Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Improve memory usage #45

Closed
straube opened this issue Mar 12, 2019 · 3 comments
Closed

Improve memory usage #45

straube opened this issue Mar 12, 2019 · 3 comments

Comments

@straube
Copy link
Owner

straube commented Mar 12, 2019

When replacing domains in big strings, it's possible that memory leaks happen. One possible way to handle that is breaking the string in smaller chunks but I'm not sure if that would actually help. I have to run some tests to see how the plugin logic behaves on those cases. Here is an example of a related issue that required memory increase: https://wordpress.org/support/topic/error-output-on-wp-json-oembed-sites-urls/.

@straube straube added this to the 1.0 milestone Mar 12, 2019
@straube straube removed the bug label Apr 15, 2019
@straube straube modified the milestones: 1.0, 1.1 Apr 19, 2019
@straube
Copy link
Owner Author

straube commented Oct 22, 2019

According to this answer on StackOverflow, it seems that mb_eregi_replace use less memory than preg_replace. I didn't benchmark them yet, but I'll definitely give a try when I have a chance.

If someone has any thoughts on this approach, please let me know.

@straube
Copy link
Owner Author

straube commented Oct 26, 2019

I could confirm that mb_eregi_replace consumes less memory when compared to preg_replace. However, it takes more time to execute. Here are the average metrics for a ~12Mb string:

mb_eregi_replace

Memory: 14.3Mb
Exec. time: 3.16s

preg_replace

Memory: 31.4Mb
Exec. time: 0.16s

Even smaller strings take around 2s with mb_eregi_replace. Perhaps we should have both options and leave for the site owner to switch between preg_replace for faster execution or mb_eregi_replace for lower memory usage.

@straube
Copy link
Owner Author

straube commented Oct 28, 2019

To enable the low memory usage mode, add the following line to the wp-config.php file:

define('MULTIPLE_DOMAIN_LOW_MEMORY', true);

Using this mode has a downside of higher execution times. The developer must weight what is best for each installation's scenario.

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

No branches or pull requests

1 participant