8000 Improve performance of script handlers by Seldaek · Pull Request #12456 · composer/composer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve performance of script handlers #12456

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

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

Seldaek
Copy link
Member
@Seldaek Seldaek commented Jun 23, 2025

Only create autoloaders when needed, and avoid creating duplicate autoloaders.

In pathological cases like declaring a post-package-install script as "Foo::bar", it would classmap-scan the whole project on every package being installed, causing 200ms of delay at every package. Trying this on a repo here this PR improves a fresh install time from 38 down to 9seconds, which is quite dramatic. I suppose other cases where large classmaps or listener-heavy plugins are present might also see significant speedups.

Targetting 2.9 though because it does carry some risk of regression in case I missed a corner.

Refs #8587

@stof
Copy link
Contributor
stof commented Jun 23, 2025

For the case in #8587 (comment), I think another improvement could be done: composer run-script (either used explicitly or through a script alias) should never need to make an autoloader, as it is not running as part of the composer installation that can change the installed packages.

@Seldaek
Copy link
Member Author
Seldaek commented Jun 23, 2025

composer run-script (either used explicitly or through a script alias) should never need to make an autoloader, as it is not running as part of the composer installation that can change the installed packages.

yeah I thought about this but it is most often used for binaries which are anyway now skipping the autoloader completely, so I don't think it is worth detecting this special case (especially as it is maybe not so easy, we lack that context inside EventDispatcher).. As creating a single autoloader is often relatively cheap, the main problem is when it keeps recreating them.

The other issue is that we do not actually load the project's autoloader, so this would fail if we do not create an autoloader inside run-script.

@Seldaek Seldaek force-pushed the event_autoload_perf branch from f983c75 to 8ead554 Compare June 23, 2025 14:25
Only create autoloaders when needed, and avoid creating duplicate autoloaders

Refs composer#8587
@Seldaek Seldaek force-pushed the event_autoload_perf branch from 8ead554 to 3372a31 Compare June 25, 2025 07:41
@Seldaek Seldaek merged commit 2ac8f49 into composer:main Jun 25, 2025
20 checks passed
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.

4 participants
0