psalm / psalm-plugin-laravel

A Psalm plugin for Laravel
MIT License
298 stars 69 forks source link

Psalm exhausted memory usage when analyzing a model use `HasRecursiveRelationships` trait from `staudenmeir/laravel-adjacency-list` #343

Closed Rizky92 closed 5 months ago

Rizky92 commented 1 year ago

Describe the bug Psalm stuck on analyzing a model that contains HasRecursiveRelationships trait from staudenmeir/laravel-adjacency-list which caused exhausted memory usage. I've set hard limit on my usage up to 2G.

Impacted Versions

barryvdh/laravel-debugbar             v3.7.0    PHP Debugbar integration for Laravel
barryvdh/laravel-ide-helper           v2.13.0   Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
diglactic/laravel-breadcrumbs         v8.1.1    A simple Laravel-style way to create breadcrumbs.
fruitcake/laravel-cors                v2.2.0    Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
lab404/laravel-impersonate            1.7.4     Laravel Impersonate is a plugin that allows to you to authenticate as your users.
laravel/dusk                          v6.25.2   Laravel Dusk provides simple end-to-end testing and browser automation.
laravel/framework                     v8.83.27  The Laravel Framework.
laravel/serializable-closure          v1.3.0    Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
laravel/tinker                        v2.8.1    Powerful REPL for the Laravel framework.
psalm/plugin-laravel                  v1.6.2    A Laravel plugin for Psalm
rap2hpoutre/laravel-log-viewer        v2.3.0    A Laravel log reader
rizky92/laravel-xlswriter             0.0.3     Laravel wrapper package for php ext-xlswriter extension
spatie/laravel-permission             5.10.1    Permission handling for Laravel 6.0 and up
spatie/laravel-ray                    1.32.4    Easily debug Laravel apps
spatie/laravel-settings               3.1.0     Store your application settings
staudenmeir/laravel-adjacency-list    v1.9.6    Recursive Laravel Eloquent relationships with CTEs
staudenmeir/laravel-cte               v1.5.5    Laravel queries with common table expressions
staudenmeir/laravel-migration-views   v1.5.1    Laravel database migrations with SQL views
vimeo/psalm                           4.30.0    A static analysis tool for finding errors in PHP applications

Additional context No known additional contexts, however I can provide more if needed.

orklah commented 1 year ago

Please try running with Psalm 5.

Also, depending on the codebase it may not be surprising for Psalm to consume that much

Rizky92 commented 1 year ago

Thank you for the reply. I'll try if it works with psalm 5. The error occured when developing for production codebase and We couldn't bump laravel just yet.

Regarding memory usage, on typical linting psalm consumes ~1G. The process stuck on that particular model that has the trait, which leads me to believe some error happening in the trait.

alies-dev commented 1 year ago

Hey @Rizky92 what is the laravel plugin version you use? in v2.6.0 we fixed a major issue that leaded to high memory consumption. This plugin version works with Laravel ^9.2: https://github.com/psalm/psalm-plugin-laravel/blob/v2.6.0/composer.json#L18 , but please let composer to install the most suitable version for your project.

UPD:

psalm/plugin-laravel v1.6.2

I see, you use v1.6.2. Can you please update both Psalm and plugin versions, as @orklah recommended?

alies-dev commented 5 months ago

Hey @Rizky92

Can you please try to use 1.x branch of the package? like:

"psalm/plugin-laravel": "dev-1.x as v1.6.3"

I just applied the same performance fix as I did on the master branch - it should have a noticeable positive impact to the memory consumption. If it works ok, I'll release it as v1.6.3. Thank you in advance!

alies-dev commented 5 months ago

UPD: the fix is released as v1.6.3. Please ping me here if something is broken on this version.