Skip to content

Improve Composer autoloader performance & security - #4

Merged
andergmartins merged 1 commit into
publishpress:mainfrom
nlemoine:fix-composer-autoloader
Oct 8, 2025
Merged

andergmartins merged 1 commit into
publishpress:mainfrom
nlemoine:fix-composer-autoloader

Conversation

@nlemoine

@nlemoine nlemoine commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

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-authoritative flag 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-authoritative flag:

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.
@nlemoine

nlemoine commented Oct 2, 2025

Copy link
Copy Markdown
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
andergmartins self-requested a review October 7, 2025 13:38
@andergmartins
andergmartins merged commit dc077d5 into publishpress:main Oct 8, 2025
@andergmartins

Copy link
Copy Markdown
Member

Hi @nlemoine thank you for the collaboration. We are working to apply this to our projects.

@nlemoine

nlemoine commented Oct 8, 2025

Copy link
Copy Markdown
Contributor Author

Thank you @andergmartins for considering this!

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