Skip to content

Cache the result of getAmbiguousFolders until a class is added - #50

Merged
Seldaek merged 1 commit into
composer:mainfrom
Seldaek:memoize-ambiguous-folders
Sep 25, 2026
Merged

Seldaek merged 1 commit into
composer:mainfrom
Seldaek:memoize-ambiguous-folders

Conversation

@Seldaek

@Seldaek Seldaek commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Caches the result of getAmbiguousFolders() per filter value on the ClassMap instance. The cache is dropped whenever addClass() or addAmbiguousClass() is called.

Composer calls it twice with the same filter: once while dumping the autoloader to print warnings, and once in dump-autoload --strict-ambiguous to pick the exit code. The walk over all paths is the expensive part, at roughly 50ms for 20k classes.

Changes made by writing to the public $map property directly are not detected, so the cache is not dropped in that case. Composer only uses addClass().

Composer checks it both while dumping the autoloader and again in the
dump-autoload command to pick the exit code, and the walk over all paths
is the costly part.
@Seldaek
Seldaek force-pushed the memoize-ambiguous-folders branch from 9f1ffc4 to 94bcda0 Compare September 25, 2026 15:17
@Seldaek
Seldaek merged commit c0efbeb into composer:main Sep 25, 2026
14 checks passed
@Seldaek
Seldaek deleted the memoize-ambiguous-folders branch September 25, 2026 15:24
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.

1 participant