Repository navigation
Improve Composer autoloader performance & security - #4
Merged
Merged
Conversation
Use `--classmap-authoritative` argument when dumping the autoloader for production. This will tell Composer autoloader to only find classes that are in the classmap and avoid looks up in other folders.
Contributor
Author
|
@andergmartins Can you take a look at this PR please? 🙏 I still have to patch your plugin to prevent the performance bottleneck. |
andergmartins
self-requested a review
October 7, 2025 13:38
Member
|
Hi @nlemoine thank you for the collaboration. We are working to apply this to our projects. |
Contributor
Author
|
Thank you @andergmartins for considering this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the WordPress ecosystem, it's common for multiple plugins to ship their own Composer autoloaders —unlike modern PHP applications that typically rely on a single, centralized autoloader. This fragmented setup increases the risk of class autoloading conflicts or failures, especially if plugins don’t use "classmap-authoritative": true or omit the
--classmap-authoritativeflag when running composer dump-autoload.Without this, Composer may fall back to scanning the filesystem using PSR-0/4 rules at runtime, which is inefficient and brittle in production (e.g. on read-only or optimized environments). By enabling classmap authoritative mode, you're telling Composer to trust only the generated classmap, resulting in faster, deterministic autoloading and fewer surprises in real-world deployments.
This is especially critical in WordPress, where plugin isolation is weak and performance matters.
On large projects where we use PublishPress Revisions Pro, this can lead the autoloader to perform multiple useless class look ups (2000+ with a 10/15ms performance penalty, profiled with BlackFire).
So far, big players like ACF and EWWW Image Optimizer did it if you have any doubt about that change.
Adding this is a small but meaningful improvement for reliability and performance.
More information about
--classmap-authoritativeflag: