Skip to content

[TypeInfo] TypeContextFactory::createFromClassName() needs a result cache #61725

@landure

Description

@landure

Symfony version(s) affected

7.3.3

Description

When validating a form on a DoctrineMongoDB ODM Document with many Collection fields, the TypeContextFactory::createFromClassName() method is called several times to parse:

It uses PHPStan Property extractor to parse the docblocks. UnitOfWork and ClassMetadata docblocks are huge. This slows the form validation.

How to reproduce

Call:

for($i=0; $i < 20; $i++) {
$this->typeContextFactory->createFromClassName("Doctrine\ODM\MongoDB\PersistentCollection","Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionTrait");
}

Possible Solution

Please add a cache to TypeContextFactory::createFromClassName() to limit resource usage due to running PHPStan property extractor on already parsed classes.

Additional Context

PHPStan Property extractor also has a resource issue when parsing type declarations with < (arrays, generics, collections). It always tries to determine if its an HTML tag, regardless of the type declaration context.

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