Skip to content

Instantly share code, notes, and snippets.

@amenk
Last active January 14, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amenk/29636622c60a420330a8b827d166f9cf to your computer and use it in GitHub Desktop.
Save amenk/29636622c60a420330a8b827d166f9cf to your computer and use it in GitHub Desktop.
XDebug Performance Problem with Magento 2.3

Setup

PHP 7.1 Magento 2.3.2-p2

bin/magento:

global $mageStart;
$mageStart = microtime(true);

\Firebear\ImportExport\Model\Import\Product::saveProducts

global $mageStart;
echo "Time until saveProducts " . (microtime(true) - $mageStart) . PHP_EOL;

(No breakpoints set before that point)

20-xdebug.ini

zend_extension=xdebug.so

xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_host=127.0.0.1
xdebug.collect_params=0
xdebug.max_nesting_level=500
xdebug.file_link_format="javascript:var rq = new XMLHttpRequest(); rq.open(\"GET\", \"//localhost:8091?message=%f:%l\", true); rq.send(null);"
xdebug.var_display_max_depth=5

Rough performance comparision

Run without Xdebug

Time until saveProducts 2.23s

Run with Xdebug 2.9.0

Time until saveProducts 228.93s

Run with Xdebug 2.7.2+2.5.5+2.8.0~beta2-1+ubuntu16.04.1+deb.sury.org+11

Time until saveProducts 43.68s

@amenk
Copy link
Author

amenk commented Jan 9, 2020

See twitter thread: https://twitter.com/derickr/status/1215212405141180416 -- it's a problem in 2.9.0

@derickr
Copy link

derickr commented Jan 13, 2020

I think I have resolved much of this in the xdebug_2_9 branch. It would be great if you could do another test run to compare times betwen 2.7.2, 2.9.0, and the xdebug_2_9 branch.

@amenk
Copy link
Author

amenk commented Jan 13, 2020

@derickr I am trying but getting Failed loading /usr/lib/php/20190902/xdebug.so: /usr/lib/php/20190902/xdebug.so: undefined symbol: zend_post_startup_cb

@derickr
Copy link

derickr commented Jan 13, 2020

Sounds like the Xdebug is compiled for the wrong PHP version then. The API NO (20190902) indicates that you're running with PHP 7.4? Are you installing Xdebug differently than what you would do for 2.9.0 ?

@amenk
Copy link
Author

amenk commented Jan 13, 2020

@derickr
Hm, I ran /usr/bin/phpize7.1 -- I have all kind of PHP version (https://launchpad.net/~ondrej/+archive/ubuntu/php) installed and want to install for PHP 7.1

Usually I use the .deb package but I believe I have to compile it from the git for testing purpose?

@amenk
Copy link
Author

amenk commented Jan 13, 2020

$ /usr/bin/phpize7.1
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

But

$ ./configure |grep 7.
checking Check for supported PHP versions... supported (7.4.1)

@amenk
Copy link
Author

amenk commented Jan 13, 2020

@derickr I had to use update-alternatives --config php-config as well

@derickr
Copy link

derickr commented Jan 13, 2020

Works now then? Otherwise, make sure you pass --with-php-config=/usr/bin/php-config7.1 (if that exists) to ./configure

@amenk
Copy link
Author

amenk commented Jan 13, 2020

@derickr

Works now ...

Beware I am on a different computer now, and have different old breakpoints (which are of course not hit before the command to get the timing).

So overall it's much faster:

other machine (self-laptop) / Different Set of (not-hit) Breakpoints

PHP 7.1, no xdebug, Time until saveProducts 1.9
PHP 7.1, xdebug Version: 2.9.0+2.5.5-1+ubuntu18.04.1+deb.sury.org+1 Time until saveProducts 78.7
PHP 7.1, xdebug Version: 2.7.2+2.5.5+2.8.0~beta2-1+ubuntu16.04.1+deb.sury.org+11 Time until saveProducts 47.97
PHP 7.1, xdebug git xdebug_2_9 a410c7847f6c8d5a15aad7dbaa55f256054b1f94 Time unitl saveproducts: 48.46

And it looks like your changes have a very good effect. Great!

I am wondering if there are any other settings to speed up Xdebug? Factor 25 is still a lot in "slow systems" like Magento ;)
I usually have buttons to phpenmod / phpdismod Xdebug in my IDE to workaround this.

@derickr
Copy link

derickr commented Jan 13, 2020

If you're not using code coverage, set xdebug.coverage_enable=0

@derickr
Copy link

derickr commented Jan 13, 2020

As a curiosity, how many breakpoints do you have configured?

@amenk
Copy link
Author

amenk commented Jan 13, 2020

If you're not using code coverage, set xdebug.coverage_enable=0

Also 47 secounds on 2.7.2

As a curiosity, how many breakpoints do you have configured?

Only 30 .. I don't clean them often

@amenk
Copy link
Author

amenk commented Jan 13, 2020

But 2.9.1-dev with all but one breakpoints cleared needs only 29s now (in contrast to 2.7.2 which did not become faster)

xdebug.coverage_enable=0 does not have too much of an effect.

@amenk
Copy link
Author

amenk commented Jan 14, 2020

@derickr on my main computer (where I did the performance stats in the first original post), I have 73 break points ...if I delete them I go down to 19s from 49s on 2.7.2

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