Skip to content

Optimize Production Composer Build to reduce needless file lookups #7337

@andyblackwell

Description

@andyblackwell

Bug Description

I recently did an optimization pass on our sites, and after profiling them found that several plugins with local composer /vendor builds were not fully optimized for production, AMP being one of these.

The plugin's local composer autoloader is not built with --classmap-authoritative, and by default the composer ClassLoader will prepend itself to the list of autoloaders. Both of these issues combined can cause thousands of needless file lookups for classes flowing through this loader that it doesn't need to handle. When not built with --classmap-authoritative and a class isn't found in the local classmap, then composer makes a few fallback attempts to find the class, resulting in all the needless file lookups.

Looks like this plugin already uses --optimize-autoloader, so would propose adding --classmap-authoritative
so adding either of these to the production build: -oa or --optimize-autoloader --classmap-authoritative

and potentially also adding prepend-autoloader: false to the composer.json config, so this autoloader doesn't prepend itself ahead of other more site specific autoloaders:

"config": {
    "prepend-autoloader": false
}

Expected Behaviour

Expected behavior is that the local composer build only handles autloading the classes it includes.

Screenshots

No response

PHP Version

No response

Plugin Version

2.3.0

AMP plugin template mode

Standard, Transitional, Reader

WordPress Version

6.0.2

Site Health

No response

Gutenberg Version

No response

OS(s) Affected

No response

Browser(s) Affected

No response

Device(s) Affected

No response

Acceptance Criteria

No response

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ChangeloggedWhether the issue/PR has been added to release notes.P0High priorityPerformance

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions