Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Di runtime definition optimisation - Cache result of processing and inline the check #6746

Conversation

nickpeirson
Copy link
Contributor

We noticed a long time was spent in runtime definitions on some of our requests and that calls to processClass could run into tens of thousands in some cases. As hasProcessedClass() was only called from one place, I've inlined it to reduce the method call and cached the result of the check, which has made a significant difference to requests that have significant numbers of calls to processClass.

`array_flip` followed by `array_keys` is much quicker than `array_unique`. We don't retain he array indices by doing this, but we don't need them in this case so can take advantage of the optimisation. Making the supertypes array unique reduces the amount of classes that DI has to work through.
@nickpeirson nickpeirson changed the title DI definition list optimisation - Cache classes upfront where possible to reduce iterations Di runtime definition optimisation - Cache result of processing and inline the check Oct 10, 2014
@Ocramius
Copy link
Member

@nickpeirson thanks for rebasing it :-)

@nickpeirson
Copy link
Contributor Author

No problem, not sure where the previous PR went astray :/ Rebasing the others now as well.

@weierophinney weierophinney added this to the 2.4.0 milestone Feb 19, 2015
@weierophinney weierophinney merged commit 56c5504 into zendframework:develop Feb 23, 2015
weierophinney added a commit that referenced this pull request Feb 23, 2015
…tion

Di runtime definition optimisation - Cache result of processing and inline the check

Conflicts:
	library/Zend/Di/Definition/RuntimeDefinition.php
weierophinney added a commit that referenced this pull request Feb 23, 2015
@weierophinney
Copy link
Member

Merged to develop for release with 2.4.

weierophinney added a commit to zendframework/zend-di that referenced this pull request May 15, 2015
…DI-RuntimeCompiler-Optimisation

Di runtime definition optimisation - Cache result of processing and inline the check

Conflicts:
	library/Zend/Di/Definition/RuntimeDefinition.php
weierophinney added a commit to zendframework/zend-di that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants