Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Config] Add ReflectionClassResource #21079

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

Closed
nicolas-grekas opened this issue Dec 28, 2016 · 7 comments
Closed

[Config] Add ReflectionClassResource #21079

nicolas-grekas opened this issue Dec 28, 2016 · 7 comments
Labels
Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Milestone

Comments

@nicolas-grekas
Copy link
Member

Q A
Feature request? yes
RFC? yes
Symfony version 3.3

When one uses autowiring, the dumped container watches many source files through FileResource objects, thus watching the mtime of referenced files.
When one is working on a class and this class is autowired, one sufferes from a big DX penalty: the container is rebuild almost everytime the user refreshed its page.
We should enhance this.
The solution seems to be to create a ReflectionClassResource that not only tracks mtimes, but also all signature related reflection info of a given class (+parents), and compares a hash of this to return isFresh only when a change is detected there also.

Would someone like to give this a try?

@nicolas-grekas nicolas-grekas added Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Dec 28, 2016
@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Dec 28, 2016
@ro0NL
Copy link
Contributor

ro0NL commented Dec 28, 2016

Doesnt one actually expect things to invalidate, when working on a class?

I understand technically we must given a changed signature, but DX-wise effectively we should only when a comment changes or so. Maybe a hash based on stripped code?

Or am i missing something?

@nicolas-grekas
Copy link
Member Author

Maybe a hash based on stripped code?

that's exactly what I mean, except that I'd not base that on stripped code, but on reflection info only.

@ro0NL
Copy link
Contributor

ro0NL commented Dec 28, 2016

I missed something. The updated code will of course run as usual in runtime. Pheww.

I like it 👍

@ro0NL
Copy link
Contributor

ro0NL commented Dec 28, 2016

The only "problem" i see is classes that are accessed before compilation and actually used in building. Changing those wont invalidate.. but that's a bad feature anyway ;-)

@dunglas
Copy link
Member

dunglas commented Dec 28, 2016

@nicolas-grekas
Copy link
Member Author

Indeed, I missed that!

@nicolas-grekas nicolas-grekas reopened this Jan 8, 2017
@nicolas-grekas nicolas-grekas changed the title [Config] Add ReflectionClassResource to speed up autowiring-enabled DX [Config] Add ReflectionClassResource Jan 8, 2017
@nicolas-grekas
Copy link
Member Author

Reopening: autowiring has AutowireServiceResource, but with closure proxies, and getter injection, we're going to need a more generic mechanism.

fabpot added a commit that referenced this issue Feb 2, 2017
…s-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI][Config] Add & use ReflectionClassResource

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #21079
| License       | MIT
| Doc PR        | -

With new changes comming to 3.3, we need a more generic reflection tracking logic than the one already managed by the autowiring subsystem.

This PR adds a new ReflectionClassResource in the Config component, and a new ContainerBuilder::getReflectionClass() method in the DI one (for fetching+tracking reflection-related info).

ReflectionClassResource tracks changes to any public or protected properties/method.

PR updated and ready, best viewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/21419/files?w=1).

changelog:

* added `ReflectionClassResource` class
* added second `$exists` constructor argument to `ClassExistenceResource` - with a special mode that prevents fatal errors from happening when some parent class is broken (logic generalized from AutowiringPass)
* made `ClassExistenceResource` also work with interfaces and traits
* added `ContainerBuilder::getReflectionClass()` for retrieving and tracking reflection class info
* deprecated `ContainerBuilder::getClassResource()`, use `ContainerBuilder::getReflectionClass()` or `ContainerBuilder::addObjectResource()` instead

Commits
-------

37e4493 [DI][Config] Add & use ReflectionClassResource
@fabpot fabpot closed this as completed Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

4 participants