Skip to content

fix: Set autoloader to be --classmap-authoritative#962

Closed
nlemoine wants to merge 1 commit intoAdvancedCustomFields:masterfrom
nlemoine:fix-autoloader
Closed

fix: Set autoloader to be --classmap-authoritative#962
nlemoine wants to merge 1 commit intoAdvancedCustomFields:masterfrom
nlemoine:fix-autoloader

Conversation

@nlemoine
Copy link
Copy Markdown

@nlemoine nlemoine commented Jun 13, 2025

This will tell your Composer autoloader to only look for classes in the declared folders (improved performance/safety).

See: https://naderman.de/slippy/slides/2017-07-13-T3DD17-Composer-Best-Practices.pdf

And: composer/composer#10205 (comment)

@nlemoine nlemoine requested a review from a team as a code owner June 13, 2025 20:21
@nlemoine
Copy link
Copy Markdown
Author

nlemoine commented Jul 2, 2025

Hello @mattgrshaw,

Can you have a look at that PR? Using composer in WordPress plugin context should be done responsibly as it can seriously hurt performance.

On a large project loading a fair amount of classes, ACF is causing a file lookup for over 4000+ classes. It's a ~15ms performance penalty on my case (profiled with Blackfire so this metric can be trusted).

Please read more about --classmap-authoritative: https://getcomposer.org/doc/articles/autoloader-optimization.md#optimization-level-2-a-authoritative-class-maps

And especially: https://getcomposer.org/doc/articles/autoloader-optimization.md#what-does-it-do--2

TL;DR; Unless you create PHP classes on the fly (which ACF don't), this PR can be merged safely and will bring benefits to all your users. It will just tell your autoloader to not look for other files (including all user/plugin/theme autoloaded PHP classes) than the ones that are in your class map.

@lgladdy
Copy link
Copy Markdown
Member

lgladdy commented Jul 4, 2025

Hey @nlemoine,

Thanks for your suggestion. We'll look to add this in our next release.

@lgladdy
Copy link
Copy Markdown
Member

lgladdy commented Jul 4, 2025

Closing the PR as we'll need to add this upstream into our build pipeline.

@lgladdy lgladdy closed this Jul 4, 2025
@nlemoine
Copy link
Copy Markdown
Author

nlemoine commented Jul 4, 2025

Awesome! Thanks @lgladdy

Looking forward to that.

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.

2 participants