Skip to content

Improve static analysis performance#2929

Merged
dantleech merged 1 commit intomasterfrom
performance
Sep 28, 2025
Merged

Improve static analysis performance#2929
dantleech merged 1 commit intomasterfrom
performance

Conversation

@dantleech
Copy link
Collaborator

@dantleech dantleech commented Sep 28, 2025

This PR removes the concept of "frame version" which was used to bust the cache whenever a variable was set. "Busting" the cache should never have been necessary in the first place due to the way that we should be traversing the AST.

Performance vs. Correctness

The way this has been done is potentially less accurate than the original solution but I'm confident the original solution was far from being correct.

In in some cases the static analysis is now twice as fast and uses less memory, for example, resolving diagnostics in a highly complex file :

Before:

594 problems in 69.3588 seconds with 162,172,464b memory

After:

599 problems in 29.8693 seconds with 104,673,608b memory

(note that PHPStan also takes around 30 seconds on this file)

Next Step

One issue seems to be the way that type assertions are applied with regards to conditional branches. Instead of searching the frame for variables before and after the if statement branches we could treat conditional branches as frames which inherit the variables of the parent. Frames can then have exit assertions which get applied automatically when leaving the frame.

dantleech added a commit that referenced this pull request Sep 28, 2025
- remove the "frame version" cache busting concept.
- change the way the if statement resolver works.
dantleech added a commit that referenced this pull request Sep 28, 2025
- remove the "frame version" cache busting concept.
- change the way the if statement resolver works.
dantleech added a commit that referenced this pull request Sep 28, 2025
- remove the "frame version" cache busting concept.
- change the way the if statement resolver works.
- remove the "frame version" cache busting concept.
- change the way the if statement resolver works.
@dantleech dantleech merged commit dafa51c into master Sep 28, 2025
11 checks passed
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.

1 participant