Skip to content

Check performance upgrade: remove dependency injection #125

@RoySegall

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');
  }

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