Skip to content

Check performance upgrade: remove dependency injection #125

Description

@RoySegall

It seems that when using a depdancy injection the objection get's really really really big. This increase memory usage and maybe caching sizes. For now we have something like this:

class Memcache extends CacheBase implements HookContainerInterface {

  /**
   * @var NuntiusConfig
   */
  protected $config;

  /**
   * @var \Memcached
   */
  protected $memcached;

  /**
   * {@inheritdoc}
   */
  static function getContainer(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
    return new static($container->get('config'));
  }

  /**
   * Memcache constructor.
   *
   * @param NuntiusConfig $config
   */
  public function __construct(NuntiusConfig $config) {
    $this->config = $config;

    $connection = $config->getSetting('memcache');

    $this->memcached = new \Memcached();
    $this->memcached->addServer($connection['host'], $connection['port']);
  }
}

will be

class Memcache extends CacheBase implements HookContainerInterface {

  /**
   * @var NuntiusConfig
   */
  protected $config;

  /**
   * @var \Memcached
   */
  protected $memcached;

  /**
   * {@inheritdoc}
   */
  static function getContainer(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
    return new static($container->get('config'));
  }

  /**
   * Memcache constructor.
   *
   * @param NuntiusConfig $config
   */
  public function __construct(ContainerBuilder $container) {
    $this->container = $container;
  }

  protected function getMemcache() {
    return new Memcache();
  }

  protected function getConfig() {
    return $this->container->get('config');
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions