Skip to content

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

Open
alfredbez wants to merge 1 commit into
rectorphp:mainfrom
alfredbez:fix/rector-perf-simplify-empty-check-cheap-guard
Open

alfredbez wants to merge 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
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.

1 participant