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
Improve performance #1837
Comments
Phan does set dynamic properties on <?php
function example($x) {
echo strlen($x);
}
example([]); Dead code detection on multiple processes was something I thought about for Phan but haven't gotten around to trying to implement. https://gist.github.com/muglug/e3b8bb7dbbec4431c71ae541f61476e6 - Phan stores inferred types in the Context because Phan analyzes the same function more than once when parameter types are missing. Caching it permanently in the Suggestions for Optimizations
|
Great idea, will do that
Yeah, I have a slightly buggy branch that is working towards that (with the ~20% speedup mentioned above). It doesn't clone - just copies the type array, and tries to clone whenever the type is changed.
this is done currently (at least for the CallMap)
I do this occasionally, was great for some early gains, but has become less so as the project has done more and more
Definitely going to try this, thanks! |
This should give a small performance boost. Part of vimeo#1837. The change is enforced via phpcs and can be autofixed with phpcbf.
This should give a small performance boost. Part of #1837. The change is enforced via phpcs and can be autofixed with phpcbf.
Another, more drastic change would be to transpile to Go. VK's Go-powered noverify is roughly 4 times faster running on Psalm's own codebase (though, due to a bug, there's no speedup when running on Vimeo's codebase). There'd be numerous challenges with such a transpilation – no plugins would work unless they, too, were transpiled. |
Closing for now as there's not much more that can be done on this front |
But @TysonAndre would you mind running phpspy on Psalm's codebase and letting me know if there's anything interesting? It's Linux-only, and I'm Apple all the way. |
Nevermind, I figured out how to get it running. The only real feedback is that |
Running in a single process* (and using Phan's fallback parser), Phan is 20% faster than Psalm. Part of that is maybe due to Psalm doing some slightly deeper analysis, but Phan is also architected to be faster in a number of ways.
Cloning var types when cloning context
A significant (~25%) speedup can be gained by not cloning Context::$vars_in_scope (which contains the known types of variables and properties in a given scope) when branching (e.g. in
if
statements,foreach
loops).Turning off this cloning introduces a numbebr of bugs, but it's likely a surmountable problem.
PHP-Parser node types
Psalm stores them on PHP Parser nodes (which uses a "feature" of PHP allowing arbitrary properties set on nodes), but Phan stores them in its Context, which is a little faster.
Example here: https://gist.github.com/muglug/e3b8bb7dbbec4431c71ae541f61476e6
cc @TysonAndre
*when checking for dead code, Psalm is faster because it can do the analysis in multiple threads
The text was updated successfully, but these errors were encountered: