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

Utils - save only unique deprecations to avoid memory issues #5695

Merged
merged 1 commit into from May 13, 2021
Merged

Utils - save only unique deprecations to avoid memory issues #5695

merged 1 commit into from May 13, 2021

Conversation

PetrHeinz
Copy link
Contributor

@PetrHeinz PetrHeinz commented May 6, 2021

With the #5674 merged, we have run into exhaustion of allowed memory pretty quickly, see https://github.com/shopsys/shopsys/pull/2308/checks?check_run_id=2511509379

Even though it would be better for us to fix all the deprecations, and we definitely plan to do it in the future, it will be rather time consuming and we would like to use the newer version in the meantime.

I propose to save the deprecation message only if it's unique. Because array_unique is called on the result afterwards, I see no issues with this approach.

@PetrHeinz
Copy link
Contributor Author

PetrHeinz commented May 6, 2021

Running array_search for every trigger of deprecation message might be inefficient as it's O(n).

Maybe using a key for ensuring the uniqueness would be better as it's O(1), but it would introduce a change of meaning into Utils::$deprecations:

    /**
     * Handle triggering deprecation error.
     *
     * @param string $message
     * @param string $exceptionClass
     */
    public static function triggerDeprecation($message, $exceptionClass = \RuntimeException::class)
    {
        if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
            throw new $exceptionClass("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
        }

-       if (false === array_search($message, self::$deprecations, true)) {
-           self::$deprecations[] = $message;
-       }
+       self::$deprecations[$message] = true;
        @trigger_error($message, E_USER_DEPRECATED);
    }

    public static function getTriggeredDeprecations()
    {
-       return self::$deprecations;
+       return array_keys(self::$deprecations);
    }

Not sure which approach is preferable for this project, so I'm just putting it there...

@keradus
Copy link
Member

keradus commented May 6, 2021

I like the proposal with assyc array. shitty we don't have native Set support

@keradus
Copy link
Member

keradus commented May 6, 2021

maybe just sort the array in getTriggeredDeprecations too

@PetrHeinz
Copy link
Contributor Author

@keradus Sure thing, done in a034c9b

@keradus keradus added this to the 2.19.1 milestone May 7, 2021
@keradus keradus added the RTM Ready To Merge label May 7, 2021
@coveralls
Copy link

coveralls commented May 7, 2021

Coverage Status

Coverage decreased (-0.005%) to 91.525% when pulling b9a839e on PetrHeinz:patch-1 into 1f0af68 on FriendsOfPHP:2.19.

s3tezsky pushed a commit to shopsys/shopsys that referenced this pull request May 13, 2021
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
@keradus keradus removed the RTM Ready To Merge label May 13, 2021
@keradus
Copy link
Member

keradus commented May 13, 2021

Thank you @PetrHeinz.

@keradus keradus merged commit f2f6e3b into PHP-CS-Fixer:2.19 May 13, 2021
s3tezsky pushed a commit to shopsys/shopsys that referenced this pull request May 14, 2021
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
s3tezsky pushed a commit to shopsys/shopsys that referenced this pull request May 14, 2021
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
s3tezsky added a commit to shopsys/shopsys that referenced this pull request May 14, 2021
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
ShopsysBot pushed a commit to shopsys/coding-standards that referenced this pull request May 14, 2021
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
ShopsysBot pushed a commit to shopsys/coding-standards that referenced this pull request Sep 22, 2023
version is excluded because of high memory usage, see PHP-CS-Fixer/PHP-CS-Fixer#5695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants