-
Notifications
You must be signed in to change notification settings - Fork 686
Improve performance by avoiding repeated scanning of files included/required only once #11478
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
base: 6.x
Are you sure you want to change the base?
Conversation
Do you have a before/after benchmark? |
I already implemented this with a config key: https://github.com/vimeo/psalm/blob/6.x/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php#L169 |
@staabm, is
...and output after this PR:
|
@danog, I did not know about |
@danog, I might give this another week, then merge it if there is no more feedback. |
The problem with making this mandatory is that in some cases, side effects are the only reason why a file is included. Also, with scan order being non-deterministic in multithreaded mode, merging this means a Psalm issue might popup randomly in any of the files where another file is included with include_once/require_once (because we might have already scanned the include before in file A, thus we ignore side effects when including in file B; but file A and B may be inverted depending on the non-deterministic scheduling order); while with ignore_include_side_effects, we always disable side effect evaluation, regardless of whether we included the file before or not. |
@danog, you are correct about the order of file loading not necessarily being the same as it would be at runtime. However, this non-deterministic behavior is comparable to composer class loading, which can happen in any number of different orders depending on when each class happens to be referenced at runtime. I think that is good evidence that this is generally a non-issue with PHP codebases. Also, it seems like it would be a very unusual edge case where this would matter for |
Decided to not merge this after all, as it introduces yet another element of non-determinism, without any strong reason in favor (performance issues can be solved using the newly added flag to ignore include side effects). I will gladly merge this if it's implemented as another optional flag. |
@danog, fair enough. I'll put this back on my TODO list and hopefully circle back to it before too long. |
@danog, I've made this an optional flag as requested. What are your thoughts? |
@danog, just checking in. |
@danog, this has been open three weeks now. If no one is interested/able to review it, I think I will just merge it after another week since you said you'd gladly approve it if it was implemented as an optional flag. |
I'm not immediately sure how to effectively add a unit test for this. If existing unit tests pass, I'll be tempted to merge it if no one has any concerns after a week or so. This significantly speeds up scans and prevents memory issues on few older projects of ours with a ton of include and/or require calls which Psalm was incorrectly interpreting to be circular. This should resolve them by more accurately mimicking actual
include_once()
andrequire_once()
behavior, instead of treating them more likeinclude()
andrequire()
. Don't hesitate to speak up if anyone has any questions/concerns.