Skip to content

Phpstan array analysis takes forever #7955

Closed

Description

@mvorisek

Bug report

In our fork, mostly identical to https://github.com/tecnickcom/TCPDF the analysis of fonts/ takes forever.

I was expecting it to be solved in v1.8.4 phpstan, but it seems the font files, mostly consisting of large arrays, are still not analysed effectively. The array shape is degraded probably not when parsing, and the full array shape is still built once which is very slow.

Code snippet that reproduces the problem

n/a, performance problem

How to reproduce:

  1. clone main branch of https://github.com/tecnickcom/TCPDF repo
  2. analyse the whole repo directory /wo fonts/ directory (and phpstan level 1) - phpstan should finish in about a minute /w about 70 errors
  3. analyse the whole repo directory again, but now incl. the fonts/ directory - phpstan takes forever (did not finish in more than 30 minutes)

Expected output

phpstan must finish in about the same time for 2. and 3. repro steps

once fixed, the TCPDF repo should be added to integration tests

Activity

  1. ondrejmirtes commented on Sep 7, 2022

    @ondrejmirtes
    Member

    How does the performance compare in PHPStan 1.8.5?

  2. mvorisek commented on Sep 7, 2022

    @mvorisek
    ContributorAuthor

    With phpstan v1.8.5 and fonts/ directory included, phpstan still does not finish.

    image

  3. enumag commented on Oct 7, 2022

    @enumag
    Contributor

    I finished my update from PHPStan 1.4 to PHPStan 1.8 and the CI runs time (when there is no result cache) went from ~24 mins to ~62 mins. 😳

  4. ondrejmirtes commented on Oct 7, 2022

    @ondrejmirtes
    Member

    @enumag This isn't helpful nor actionable. Run with -vvv --debug, find which file takes the longest, isolate the problem, and open a separate issue.

  5. bart-mollie commented on Oct 10, 2022

    @bart-mollie

    I'm running into a similar issue on my codebase, and have created a small sample here to show the structure that phpstan hangs on. The playground times out when the array contains about 2000 values. https://phpstan.org/r/46a17e15-22a3-414a-b8d7-c27617d5ac5b.

    If a longer sample is needed, I've attached a txt file with the same class with 10k values that takes 66 seconds to analyse on my machine. Our codebase contains multiple of these maps, and since the upgrade we did from from 1.8.2 to 1.8.8, the CI pipelines times out.

    Thanks for all the hard work you're putting into this project, it's absolutely amazing and a complete paradigm shift for php.

    HugeMapClass.php.txt

  6. rvanvelzen commented on Oct 10, 2022

    @rvanvelzen
    Contributor

    @bart-mollie the slowness in your example code is from analysing the array_search call. It's not the same issue, but perhaps some other examples from your codebase are. Please create a separate issue for this.

  7. bart-mollie commented on Oct 10, 2022

    @bart-mollie

    Thanks for looking into it! I've created #8147

  8. staabm commented on Dec 12, 2022

    @staabm
    Contributor

    @mvorisek could you double check with the latest development version?

    if it is still slow, could you extract the actually slow files so I can reproduce easily?

    you may utilize https://gist.github.com/ruudk/41897eb59ff497b271fc9fa3c7d5fb27

  9. mvorisek commented on Dec 12, 2022

    @mvorisek
    ContributorAuthor
  10. ondrejmirtes commented on Dec 20, 2022

    @ondrejmirtes
    Member

    Should be fast now. Please test PHPStan 1.9.5 once it's released :)

  11. mvorisek commented on Dec 20, 2022

    @mvorisek
    ContributorAuthor

    Let's keep this issue open until released. If ok, I will be happy to provide a regression test for it then as this caused a lot of trouble for me in the past. Thank you.

  12. ondrejmirtes commented on Dec 20, 2022

    @ondrejmirtes
    Member

    @mvorisek I couldn't test your linked commit because the branch probably got deleted, or it's in a different fork.

    Anyway, this thread got too long, I want people to open new issues with specific examples. I believe many examples from this thread are fixed.

  13. mvorisek commented on Dec 20, 2022

    @mvorisek
    ContributorAuthor

    @ondrejmirtes see tecnickcom/TCPDF@37aa6ee last week merged officially to TCPDF - so how to test? clone https://github.com/tecnickcom/TCPDF.git and remove fonts/ from excludePaths in the phpstan config

  14. ondrejmirtes commented on Dec 20, 2022

    @ondrejmirtes
    Member

    You can now compare 1.9.4 vs 1.9.x-dev and report back.

  15. mvorisek commented on Dec 21, 2022

    @mvorisek
    ContributorAuthor

    I can confirm now TCPDF finish in a few minutes. Thank you.

  16. github-actions commented on Jan 22, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  17. locked as resolved and limited conversation to collaborators on Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions