Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Autowiring is very slow for large excluded directoriesΒ #26736

Closed
@glynnforrest

Description

@glynnforrest
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4.*

I'm experiencing a significant slowdown from autowiring when there are large directories in a bundle (e.g. node_modules), even when those directories are excluded.

This configuration is slow:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    AppBundle\:
        resource: '../../src/AppBundle/*'
        exclude: '../../src/AppBundle/{Entity,Resources,Repository,Tests,node_modules}'

This one isn't, but has the downside of adding each directory to resource manually.

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    AppBundle\:
        resource: '../../src/AppBundle/{Publisher,Locator,Foo,Bar}'

My poorly educated guess is that the GlobResource in the config component iterates through all the possibilities first, before they are filtered out by the exclude pattern? This would explain the slowdown.

foreach (glob($this->prefix.$this->pattern, defined('GLOB_BRACE') ? GLOB_BRACE : 0) as $path) {

Do you think it would be possible to prevent the glob loader searching through excluded directories?

The problem is so bad that I occasionally get out of memory errors in dev:

[Sun Apr 01 19:24:47.554299 2018] [:error] [pid 4298] [client 192.168.10.1:62972] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 130968 bytes) in /var/www/project/vendor/symfony/config/Resource/GlobResource.php on line 105

Thanks very much for adding autowiring to Symfony. It has made development so much faster! πŸŽ‰

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions