Rector: `rector --version` is super slow

Created on 28 Nov 2020  路  6Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | 0.8.56 |
| Installed as | composer dependency via global command |

invoking rector even without doing transformations is super slow.
actually all rector commands are slow on my machine, but I guess for a minimal repro it would be great to just get rector --version fast.

I am wondering why the symfony container get dumped every time and is not persisted. is this the normal thing how it is expected to work?

Minimal PHP Code Causing Issue

$ time php /c/Users/staabm/AppData/Roaming/Composer/vendor/rector/rector/bin/rector --version
Rector 0.8.56

real    0m46.023s
user    0m0.015s
sys     0m0.077s

blackfire profile

https://blackfire.io/profiles/2fed9c66-6fd4-4a37-a3b5-92e5bb2f4c3b/graph (might break after 30 days)

grafik

it seems the container gets dumped over and over on every invocation

Expected Behaviour

running rector --version should be nearly instant

$ php -v
PHP 7.3.0 (cli) (built: Dec  6 2018 02:17:00) ( ZTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
    with blackfire v1.24.1~win-x32-zts73, https://blackfire.io, by Blackfire

All 6 comments

@nicolas-grekas do you have a hint what could be the reason that the symfony container need to do so much IO?

I don't sorry. Looking at the graph, there is some globbing happening, but I can't tell what this is for...

Global install is not supported. Does this happen in composer require?

I get similar profiles on other VMs, in which the dependency is added on a per project basis:

$ blackfire run vendor/bin/rector                                                                                                                                                                             
Rector 0.8.49

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -c, --config=CONFIG            Path to config file [default: "/cluster/www/www                                                                                                                                                                             /www/rector/rector.php"]
      --debug                    Enable debug verbosity (-vvv)
      --xdebug                   Allow running xdebug
      --clear-cache              Clear cache
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as workin                                                                                                                                                                             g directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for norma                                                                                                                                                                             l output, 2 for more verbose output and 3 for debug

Available commands:
  dump-rectors  [DOCS] Dump overview of all Rectors
  generate      [c|create|g] [DEV] Create a new Rector, in a proper location, wi                                                                                                                                                                             th new tests
  help          Displays help for a command
  init          Generate rector.php configuration file
  list          Lists commands
  process       [rectify] Upgrade or refactor source code with provided rectors
  show          Show loaded Rectors with their configuration

Blackfire Run completed
Graph                 https://blackfire.io/profiles/e06af998-d71e-49df-a933-0b5d                                                                                                                                                                             f38eabac/graph
Timeline              https://blackfire.io/profiles/e06af998-d71e-49df-a933-0b5d                                                                                                                                                                             f38eabac/graph?settings%5Bdimension%5D=timeline
No tests!             Create some now https://blackfire.io/docs/cookbooks/tests
No recommendations

Wall Time  1min 55s
I/O Wait      53.8s
CPU Time    1min 1s
Memory        123MB
Network         n/a     n/a     n/a
SQL             n/a     n/a

grafik

just added some echos got the following glob patterns used currently:
(on my windows 10 workstation)

I am running php bin/rector within the rector project folder:

string(58) "C:\dvl\GitHub\rector\config/../packages/**/config/config.*"
string(55) "C:\dvl\GitHub\rector\config/../rules/**/config/config.*"
string(40) "C:\dvl\GitHub\rector\config/services.php"
string(57) "C:\dvl\GitHub\rector\config/../utils/**/config/config.php"

I think we can ignore the mixed slashes/backslashes.
do we really need the double ** globs here, which lead to deep-recursion thru the whole filesystem?

doing the same on my ubuntu VM I get

string(65) "/cluster/www/www/www/rector/config/../packages/**/config/config.*"
float(1.1577801704407)
string(62) "/cluster/www/www/www/rector/config/../rules/**/config/config.*"
float(8.748389005661)
string(47) "/cluster/www/www/www/rector/config/services.php"
float(0.14232301712036)
string(64) "/cluster/www/www/www/rector/config/../utils/**/config/config.php"
float(0.26675891876221)

the floats is the microtime spent in seconds.
overall on my ubuntu VM a simple php bin/rector takes ~30 seconds.

it seems the glob-patterns are coming from https://github.com/rectorphp/rector/blob/f38dc68649099bd8edb97f21d0e8a418f676d57e/config/config.php#L10-L13

It seems fixed by https://github.com/rectorphp/rector/pull/4743

I am closing it.

Was this page helpful?
0 / 5 - 0 ratings