Skip to content

refactor: memoize fixer names#9219

Merged
keradus merged 4 commits intoPHP-CS-Fixer:masterfrom
mlocati-forks:cache-fixer-names
Nov 30, 2025
Merged

refactor: memoize fixer names#9219
keradus merged 4 commits intoPHP-CS-Fixer:masterfrom
mlocati-forks:cache-fixer-names

Conversation

@mlocati
Copy link
Copy Markdown
Contributor

@mlocati mlocati commented Nov 25, 2025

The getName() method of fixers may be called more than once (for example, in a custom implementation of mine related to #9107).

That about caching its result?

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 25, 2025

Coverage Status

coverage: 93.389% (+0.006%) from 93.383%
when pulling db96f34 on mlocati-forks:cache-fixer-names
into a1846ee on PHP-CS-Fixer:master.

Copy link
Copy Markdown
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

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

open for it, yet wondering if there is any actual impact on performance.

then, if moving this direction, why not in constructor and mark the "cached" property @readonly ?

@mlocati
Copy link
Copy Markdown
Contributor Author

mlocati commented Nov 25, 2025

I haven't measured the performance, but I guess that repeating all the calls done by getName() for every fixer and every file (in the case of RuleCustomizationPolicyInterface for example) won't be impact less.
In any case, in most of the use cases the getName method won't never be called, that's why I made this PR this way.
But of course I can update it so that we have a @readonly property.

@mlocati
Copy link
Copy Markdown
Contributor Author

mlocati commented Nov 29, 2025

why not in constructor and mark the "cached" property @readonly ?

Done in 700356c

@mlocati mlocati changed the title chore: Memoize name calculation in AbstractFixer::getName() chore: memoize fixer names Nov 29, 2025
Comment thread src/AbstractFixer.php
Co-authored-by: Dariusz Rumiński <dariusz.ruminski@gmail.com>
@keradus keradus changed the title chore: memoize fixer names refactor: memoize fixer names Nov 30, 2025
@keradus keradus merged commit 053d01a into PHP-CS-Fixer:master Nov 30, 2025
32 of 33 checks passed
@keradus
Copy link
Copy Markdown
Member

keradus commented Nov 30, 2025

thank you

@mlocati mlocati deleted the cache-fixer-names branch November 30, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants