Skip to content
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

PHPMD does Timeouts in PhpStorm #753

Open
ravage84 opened this issue Apr 17, 2020 · 1 comment
Open

PHPMD does Timeouts in PhpStorm #753

ravage84 opened this issue Apr 17, 2020 · 1 comment

Comments

@ravage84
Copy link
Member

Windows 7, PHP 7.1.x, PHPMD 2.8.1 & PDepend 2.7.1 (composer)

In PhpStorm, for example 2019.3, PHPMD can be configured as one of its "Quality Tools", e.g. through being a Composer dependency.

When it is activated, under Windows, it often leads to timeouts, especially if one has bigger and/or many projects.

An error message will be displayed:PHP Mess Detector phpmd: Can not correctly run the tool with parameters.

grafik

I found out the cause of this is the PDepend's cache folder being too large, thus leading to increased execution time which will go beyond the configured timeout threshold setting (up to 30 seconds) in PhpStorm.

PHPMD & PDepend have a long history of various issues with its caching mechanism (in no particular order):

#184
#52
#90
#29
pdepend/pdepend#447
pdepend/pdepend#307
pdepend/pdepend#465
pdepend/pdepend#193
pdepend/pdepend#181
pdepend/pdepend#90
pdepend/pdepend#87
pdepend/pdepend#94
pdepend/pdepend#19

Comments on the following three issues helped me find the cause of & the solution to my issue:

pdepend/pdepend#307
#94 (comment)
#29 (comment)

If a file named pdepend.xml or pdepend.xml.dist exists in the current working directory where you run phpmd, then you can configure pdepend as you like.

Documented on https://github.com/pdepend/pdepend/blob/2.7.1/src/site/rst/documentation/handbook/configuration/index.rst#cache

<?xml version="1.0"?>
<symfony:container xmlns:symfony="http://symfony.com/schema/dic/services"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://pdepend.org/schema/dic/pdepend"
                   xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
                                       http://pdepend.org/schema/dic/pdepend http://pdepend.org/schema/1.0/configuration.xsd">
    <config>
        <cache>
            <driver>memory</driver>
        </cache>
    </config>
</symfony:container>

After doing so, I ran some benchmark by analyzing a small to medium sized project.

Using file cache (no pdepend.xml.dist):

  • Total time: 3 minutes 4 seconds, 183 MB peak RAM (cache re-build)
  • Total time: 1 minute 47 seconds, 103 MB peak RAM (cache existed)
  • Total time: 1 minute 47 seconds, 100-109 MB peak RAM (cache existed)
    Cache size: 2'974 files, 303 folders, 168 MB RAM
  • Total time: 3 minutes 3 seconds, 183-202 MB peak RAM (cache reset)
  • Total time: 1 minute 46 seconds, 99-110 MB peak RAM(cache existed)
    Cache size: 2'974 files, 303 folders, 168 MB RAM

Using memory cache (set through pdepend.xml.dist):

  • Total time: 1 minute 31 seconds, 171 MB peak RAM
  • Total time: 1 minute 31 seconds, 172 MB peak RAM
  • Total time: 1 minute 30 seconds, 171 MB peak RAM
  • Total time: 1 minute 31 seconds, 172 MB peak RAM

Memory Cache is (unsurprisingly) faster, uses ~1.5 times the RAM compared to file cache, if the cache already exists.
Both start around 23-25 MB RAM.

Using the memroy cache also improved the performance of PHPMD & PDepend in our local Jenkins environment.

This leads me two two questions:

  1. Is there a way to improve the behavior & performance of the caching mechanism of PDepend?
  2. Shall we switch to the memory cache driver by default?

Also, we might want to consider that there are at least two main scenarios for caching in PHPMD/PDepend:

  1. A mostly static code base that gets checked over and over (e.g Continuous integration envirornment)
  2. Fast reoccuring checks of ever changing code (e.g. in IDEs like PhpStorm)

These two scenarios are so different that in 1. a cache might make sense, but in 2. it very likely does not.

@ravage84
Copy link
Member Author

On the other side, for a big project with 8405 analyzed files in our Jenkins environment PDepend got three times slower and used over 7 times more memory:

With file cache
Time: 0:00:33; Memory: 60.00Mb
With memory cache:
Time: 0:01:31; Memory: 430.00Mb

Unfortunately, I do not have a comparison for PHPMD on this project.

@tvbeek tvbeek modified the milestones: 2.9.0, 2.10.0 Sep 2, 2020
@kylekatarnls kylekatarnls modified the milestones: 2.10.0, 2.11.0 Apr 11, 2021
@kylekatarnls kylekatarnls modified the milestones: 2.11.0, 2.12.0 Nov 27, 2021
@kylekatarnls kylekatarnls modified the milestones: 2.12.0, 2.13.0 Jun 19, 2022
@kylekatarnls kylekatarnls modified the milestones: 2.13.0, 2.14.0 Sep 10, 2022
@kylekatarnls kylekatarnls removed this from the 2.14.0 milestone Sep 27, 2023
@kylekatarnls kylekatarnls added this to the 2.15.0 milestone Sep 27, 2023
@kylekatarnls kylekatarnls modified the milestones: 2.15.0, 2.16.0 Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment