FakerPHP / Faker

Faker is a PHP library that generates fake data for you
https://fakerphp.github.io
Other
3.55k stars 341 forks source link

Memory leak since 1.14.0 #390

Closed elnur closed 2 years ago

elnur commented 2 years ago

Summary

We have over 3K tests in our project. Once I've upgraded Faker from 1.13.0 to 1.16.0, tests started exhausting memory around test 130, which is pretty soon. I downgraded until I reached 1.14.0 and the problem still persisted. Downgrading to 1.13.0 makes the problem go away.

BTW, doubling the PHP CLI memory from 2GiB to 4GiB didn't help.

Versions

Version
PHP 8.0.12
fakerphp/faker 1.14.0

Self-enclosed code snippet for reproduction

Here's the base class all test classes extend:

class TestCase extends \PHPUnit\Framework\TestCase
{
    public static Generator $faker;

    public static function initialize(): void
    {
        self::$faker = self::$faker ?? Factory::create();
    }

    protected function setUp(): void
    {
        parent::setUp();

        self::$faker->unique(true);
    }
}

initialize() is called from PHPUnit bootstrap file. Then used unique values are being reset before each test.

Expected output

OK (3333 tests, 7656 assertions)

Actual output

PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 69632 bytes) in /srv/vendor/fakerphp/faker/src/Faker/Provider/Base.php on line 200
PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 32768 bytes) in /srv/vendor/symfony/var-dumper/Cloner/VarCloner.php on line 1
pimjansen commented 2 years ago

Can you pinpoint where it is coming from? Its hard to say from the snippet i guess that somewhere in those tests the memory is increasing.

Is it always the same test or?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions.

elnur commented 1 year ago

Finally figured it out while figuring out a similar problem while upgrading to PHP 8.2. Turns out the massive number of deprecation warnings consumed a lot of memory.