Skip to content

Suggestion to increase performance of $container->get(), $container->has() and $container->make() #531

@holtkamp

Description

@holtkamp

When in the process of increasing performance of our application, I noticed two things:

  • fetched Definitions are not (locally) cached, for instance in a local array property $acquiredDefinitions[$name] => $definition
  • array_key_exists() is used, while isset() tends to perform better, although:
    • it is considered a micro-optimization...
    • when the value equals NULL it will be considered 'not set'

What do you think? Would a PR on this make sense? It can be as easy as:

private function getDefinition($name)
{
    if(!array_key_exists($name, $this->acquiredDefinitions)){
        $this->acquiredDefinitions[$name] = $this->definitionSource->getDefinition($name);
    }

    return  $this->acquiredDefinitions[$name];
}

Maybe $lookedUpDefinitions or $fetchedDefinitions is a better name for the property...

Attached a part of a BlackFire.io profiling session of the current situation.

screen shot 2017-10-30 at 13 44 36

Adding this local cache reduces the amount of lookups with around 390 calls.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions