Skip to content

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented Sep 3, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

After profiling container compilation, I noticed that ReflectionMethod::getPrototype() accounts for a significant percentage of the total time:

Screenshot from 2025-09-03 12-51-13

Instead of calling ReflectionMethod::getPrototype() each time and wrapping it in a try/catch, this PR switches to using ReflectionMethod::hasPrototype().

Here are some stats before and after this change:

Before

$ rm -rf var/cache/dev/*
$ time bin/console

Symfony 7.3.3 (env: dev, debug: true)

real    1m4.682s
user    1m1.326s
sys     0m3.330s


$ rm -rf var/cache/prod/*
$ time bin/console -e prod

Symfony 7.3.3 (env: prod, debug: false)

real    0m59.614s
user    0m57.520s
sys     0m2.033s

After

$ rm -rf var/cache/dev/*
$ time bin/console

Symfony 7.3.3 (env: dev, debug: true)

real    0m24.026s
user    0m21.909s
sys     0m2.109s


$ rm -rf var/cache/prod/*
$ time bin/console -e prod

Symfony 7.3.3 (env: prod, debug: false)

real    0m22.439s
user    0m21.256s
sys     0m1.138s

As far as I know, optimizations are considered features rather than bug fixes. If I'm wrong, please let me know and I'll retarget to 6.4.

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

ReflectionMethod::hasPrototype() was introduced in PHP 8, that's for sure why it was not used it when this code was introduced in Symfony 3.4.

You're right, the perf improvements must target the next minor version.

@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit bae2c06 into symfony:7.4 Sep 3, 2025
10 of 12 checks passed
@HypeMC HypeMC deleted the optimize-autowirerequiredmethodspass branch September 3, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants