Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Production Composer Build to reduce needless file lookups #7337

Closed
andyblackwell opened this issue Nov 10, 2022 · 4 comments · Fixed by #7362
Closed

Optimize Production Composer Build to reduce needless file lookups #7337

andyblackwell opened this issue Nov 10, 2022 · 4 comments · Fixed by #7362
Labels
Changelogged Whether the issue/PR has been added to release notes. P0 High priority Performance
Milestone

Comments

@andyblackwell
Copy link

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

@andyblackwell andyblackwell added the Bug Something isn't working label Nov 10, 2022
@westonruter westonruter added Performance and removed Bug Something isn't working labels Nov 10, 2022
@westonruter westonruter added this to the v2.3.1 milestone Nov 10, 2022
@westonruter
Copy link
Member

Thank you for this. Closely related to #7324 which we're also investigating right now.

@thelovekesh
Copy link
Collaborator

QA Passed ✅

There are file lookups when we execute composer install --no-dev -o:
image

There are no file lookups when we execute composer install --no-dev -oa(i.e. composer autoload is build with --classmap-authoritative):
image

@westonruter
Copy link
Member

Wow! How did you generate those graphs?

@thelovekesh
Copy link
Collaborator

Used Xdebug profiler(wp-env) and visualized them using KCachegrind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. P0 High priority Performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants