-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection][VarExporter] Generate lazy-loading virtual proxies for non-ghostable lazy services #47236
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
Conversation
603bf18
to
c863918
Compare
c863918
to
f790bb9
Compare
ce2a8a2
to
95a92da
Compare
This looks very interesting. While we are using the I currently workaround it by using So I thought if it would be possible to set something lazy only for a specific service: <service id="sulu_messenger.lock_middleware" class="LockMiddleware">
<argument type="service" id="lock.factory" lazy="true" />
</service> Or what would be your recommendation in this kind of case? |
IIRC, we read the middleware stack iteratively, aka we instantiate individual middleware layers on demand. Is this broken?
That's The use case for this interface so it's perfectly fine.
Yes, that's the kind of innovations that having this in core would allow! |
6a4743f
to
961b521
Compare
src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/FinalPublicClass.php
Outdated
Show resolved
Hide resolved
7980f1b
to
53cd184
Compare
src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php
Outdated
Show resolved
Hide resolved
53cd184
to
0074ef4
Compare
For the record I had a look to split lazy-traits from var-exporter and honestly there's too much code is common. Splitting would double the maintenance effort and bugs would need to be solved twice. Making one depend on the other would require opening APIs that are currently internal. I tried I promise, but technically, this is not sound to me. |
20e1df3
to
3d29386
Compare
…table lazy services out of the box
3d29386
to
4862139
Compare
Thank you @nicolas-grekas. |
This PR was merged into the 6.2 branch. Discussion ---------- [Cache] make `Redis*Proxy` extend `Redis*` | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #47267, #42428 | License | MIT | Doc PR | - `Redis*Proxy` did not extend native classes because we missed the code infrastructure to generate appropriate proxies. With #47236, we now have it. This PR adds generated proxies to the cache component to keep it lazy-able out of the box. Commits ------- cfb46ed [Cache] make `Redis*Proxy` extend `Redis*`
Since #46752 and #46751, we are able to make services lazy out of the box, except when 1. a service relies on an internal class 2. a service has the
proxy
tag or 3. a service's class is abstract (and the service uses a factory). In these situations, proxy-manager-bridge was required. This was an acceptable trade-off because this would be quite uncommon. But while working on Doctrine, I realized that we cannot use ghost objects when a factory is used. I described this for Doctrine in doctrine/orm#9896 but the situation can happen with any services constructed by a factory. This means we'd need proxy-manager-bridge anytime a factory is used on a lazy service. What was uncommon becomes quite common and the trade-off is not acceptable anymore. Thus this PR.This PR adds a
LazyProxyTrait
and aProxyHelper
to build lazy loading virtual proxies at will. It then wires this new capability into the container. As a result proxy-manager-bridge is not needed anymore. We can deprecate it in another PR.While the diff is quite big,
LazyProxyTrait
has many similarities withLazyGhostTrait
and both traits can be diffed to see where their behavior varies.Excerpt from the README for the record: