Skip to content

Conversation

@landure
Copy link
Contributor

@landure landure commented Sep 16, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #61725
License MIT

Add caches to TypeContextFactory method to prevent multiple parsing of the same classes by PHPStan property extractor.

  1. Add cache to intermediate TypeContext creation from createFromClassName() and createFromReflection() by adding:

    • intermediateTypeContextCache proprety.
    • createIntermediateTypeContext() create the intermediate TypeContext if not found in cache.
  2. Add cache to createFromClassName() by:

    • typeContextCache proprety.
    • extracting TypeContext creation to private createNewInstanceFromClassName() method.
    • refactoring createFromClassName() to get the TypeContext from $this->typeContextCache, or creating it by calling createNewInstanceFromClassName() method.
  3. Add a test to check that the results are cached.

This optimize deserialization and form validation.

@OskarStark OskarStark changed the title [TypeInfo] Add result cache to TypeContextFactory [TypeInfo] Add result cache to TypeContextFactory Sep 16, 2025
@landure landure force-pushed the 61725-type-context-factory-caching branch 2 times, most recently from 8a9f8b5 to a29f10b Compare September 16, 2025 08:27
@nicolas-grekas nicolas-grekas modified the milestones: 7.3, 7.4 Sep 16, 2025
@landure landure force-pushed the 61725-type-context-factory-caching branch 2 times, most recently from defb034 to cb47384 Compare September 16, 2025 08:37
Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 7.4 as this is a performance improvement.

Add a cache to  method with the aims to optimize
deserialization and form validation.

Closes symfony#61725
@fabpot fabpot changed the base branch from 7.3 to 7.4 September 17, 2025 05:44
@fabpot fabpot force-pushed the 61725-type-context-factory-caching branch from cb47384 to e39963f Compare September 17, 2025 05:44
@fabpot
Copy link
Member

fabpot commented Sep 17, 2025

Thank you @landure.

@fabpot fabpot merged commit cc7090f into symfony:7.4 Sep 17, 2025
11 of 12 checks passed
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants