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

Removal of CONSTANT_SCALAR_UNION_THRESHOLD causing out-of-memory condition #5527

Closed
27pchrisl opened this issue Aug 24, 2021 · 5 comments
Closed

Comments

@27pchrisl
Copy link

Bug report

Hi, since 0.12.95 I have a PHP file that is causing very long run times, eventually terminating in an out-of-memory condition where previously it was super fast and used less than 1GB. This snippet will also cause a timeout in the playground.

I have narrowed it down to the below piece of a Base64 decoder, and it's the adding of the four lines at the end of the function that is causing the issue. As you delete the last lines of the function one at a time performance improves. Using all four lines causes PHPStan to run out of memory.

<?php

class Base64
{
    const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

    public function decode()
    {   
        $chars = array_flip(str_split(self::chars));

        $buf = '';

        $res = $chars[$buf[0]] << 18;
        $res += $chars[$buf[1]] << 12;
        $res += $chars[$buf[2]] << 6;
        $res += $chars[$buf[3]];
    }
}

I was able to git bisect the issue down to commit phpstan/phpstan-src@c56d866

Current output is:

../phpstan-src/bin/phpstan analyse src/Helper/Base64.php --memory-limit 1G --level 1
PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 536870920 bytes) in /Users/chrisl/Code/phpstan-src/src/Analyser/MutatingScope.php on line 1106
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 536870920 bytes) in /Users/chrisl/Code/phpstan-src/src/Analyser/MutatingScope.php on line 1106

Did PHPStan help you today? Did it make you happy in any way?

PHPStan is great!

@mergeable
Copy link

mergeable bot commented Aug 24, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@27pchrisl
Copy link
Author

Possibly the same issue as #5524

ondrejmirtes added a commit to phpstan/phpstan-src that referenced this issue Aug 25, 2021
@ondrejmirtes
Copy link
Member

Thank you! Did some optimization: phpstan/phpstan-src@a6ca5f7

@27pchrisl
Copy link
Author

Confirmed thanks!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants