Skip to content

[perf] Speed up SimplifyEmptyCheckOnEmptyArrayRector with cheap guards before ScopeFetcher - #8795

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
alfredbez:fix/rector-perf-simplify-empty-check-cheap-guard
Oct 24, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
alfredbez:fix/rector-perf-simplify-empty-check-cheap-guard

Conversation

@alfredbez

Copy link
Copy Markdown
Contributor

In SimplifyEmptyCheckOnEmptyArrayRector, refactor() invoked ScopeFetcher::fetch($node) immediately at the start for every BooleanNot and Empty_ node in the codebase. For boolean negations where the child expression is not empty(), and for empty() expressions whose argument is not a variable or property fetch, scope resolution was performed unnecessarily.

Reproducer

class Subject
{
    public function run(bool $flag): void
    {
        if (!$flag) {
            return;
        }

        if (empty(getValues())) {
            return;
        }
    }
}

Expected Behavior

SimplifyEmptyCheckOnEmptyArrayRector should perform cheap node checks and reject unsupported node shapes (such as BooleanNot without Empty_, or non-variable/property expressions) before fetching node scope.

@alfredbez
alfredbez force-pushed the fix/rector-perf-simplify-empty-check-cheap-guard branch from 637cf24 to cf00ba2 Compare October 23, 2026 23:21
@TomasVotruba
TomasVotruba merged commit 72349ee into rectorphp:main Oct 24, 2026
49 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants