Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
[5.1] Fix contextual bindings when instances and aliases are involved #15637
Yeah, I definitely thought about that part of it. I haven't done any testing with Blackfire.io to see what the impact actually is. I'll do that today if I can get to it.
It might require some internal structural changes to alleviate any performance issues. The alias list the container keeps is keyed the the opposite direction for this particular use case.
My original implementation modified the contextual binding when defining it but this does not work if the alias is defined after the binding is created.
Did a test of the current 5.1 container versus the one in this PR:
Yeah. 42x slower. That's not even remotely acceptable.
I'm making some changes which appear to bring that number back down to ~1.6s. Unfortunately the container must keep a second array of aliases with the same information (but flipped / regrouped). I'll keep exploring the possibilities here and update this PR when I've got things ready.
All numbers are reflective of PHP 7.0.11 on:
I'd definitely say it is because the container is currently ignoring what you are telling it to do under a very specific situation.
This is a general proclamation of "when I ask for
The container acting like this is somewhat understandable because you've registered an instance under the exact thing that was asked for by the contextual binding but it is still super unintuitive because in the end: it is ignoring what I've asked of it
This is just such a weird edge case that it doesn't make sense for the container to completely ignore what I've asked it to do.
And just from a glance fixing item 2 without fixing item 1 would probably require a fairly large amount of refactoring.
All this being said:
referenced this pull request
Sep 30, 2016
Yes. Sorry. I did a bit more testing and everything looks good. Haven't had time to finish this up.
The two sets of aliases need to always stay in sync. I believe that was the last thing on my list.
I have had a look through tonight and I have added a test to check that the aliasAbstract property is flushed along with the aliases property thecrypticace#1 .
Apart from that I don't see any other area's the two properties could go out of sync. I thought there could be an issue with https://github.com/thecrypticace/framework/blob/patch-6-for-51/src/Illuminate/Container/Container.php#L339 but I couldn't write a which failed
I left some feedback on the PR. I cannot write a test at all which will fail when the lists are kept in sync. There is a scenario which could give rise to it but it is currently not supported and may not be feasible to ever be (well — barring a major refactor).
It's a scenario that's super unlikely to ever come up in practice anyway. (see thecrypticace#1 (comment))
So if something needs to be contextually built can it ever be bound as an instance after this PR? For example if I want a controller method to have