sebastianbergmann / recursion-context

Provides functionality to recursively process PHP variables
BSD 3-Clause "New" or "Revised" License
6.52k stars 18 forks source link

Out of memory errors with phpdbg coverage #3

Closed matt-allan closed 7 years ago

matt-allan commented 8 years ago

Hello,

While generating coverage data with phpdbg, I am experiencing an issue where php's memory usage climbs exponentially until exhaustion. This only happens in some cases and depends on the code being tested or executed in the test.

Reproduction steps:

git clone https://github.com/yuloh/phpdbg-bug-demo/tree/fix-test
cd phpdbg-bug-demo
composer install
phpdbg -qrr vendor/bin/phpunit --coverage-text

Expected results:

The tests should run and generate coverage.

Actual results:

If the memory_limit is set, the tests will quickly reach the memory limit and the process is killed. If the memory_limit is set to -1, the tests will slowly consume more memory while using > 90% CPU.

I raised the issue with phpdbg here:

https://github.com/krakjoe/phpdbg/issues/159

if I'm understanding correctly, phpdbg's oplog is being passed to SebastianBergmann\RecursionContext\Context::containsArray. The search is O(n^2) and the search space is really huge. It's impossible to keep up with the oplog, so the test runs incredibly slow and runs out of memory before it finishes.

sebastianbergmann commented 8 years ago

Re: @bwoebi https://github.com/sebastianbergmann/php-code-coverage/issues/474#issuecomment-255116142 A pull request that improves this would be much appreciated ;-)

bwoebi commented 8 years ago

@sebastianbergmann I'm not certain what you are trying to do there. It looks a bit like you're trying to detect recursive arrays?

If that's the case, you could just add an element to the array (e.g. an object), check if it exists (if (end($array) === $myObject)) and remove it again later on. Or were there issues with that approach?

bwoebi commented 7 years ago

@sebastianbergmann Can you please check #4 ?

matt-allan commented 7 years ago

Thanks @bwoebi and @sebastianbergmann, I really appreciate it 😄