Skip to content

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

@27pchrisl

Description

@27pchrisl

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions