Skip to content

Loading translation resources performances #13556

Closed
@umpirsky

Description

@umpirsky

I was profiling Sylius recently, and noticed that there is some time wasted on each request on adding resources to translator service.

We have a lots of resources in Sylius (around 2000), but also don't see the reason to add each of them in production mode like this:

// app/cache/prod/appProdProjectContainer.php

protected function getTranslator_DefaultService()
{
    $this->services['translator.default'] = $instance = new \Symfony\Bundle\FrameworkBundle\Translation\Translator($this, new \Symfony\Component\Translation\MessageSelector(), array('translation.loader.php' => array(0 => 'php'), 'translation.loader.yml' => array(0 => 'yml'), 'translation.loader.xliff' => array(0 => 'xlf', 1 => 'xliff'), 'translation.loader.po' => array(0 => 'po'), 'translation.loader.mo' => array(0 => 'mo'), 'translation.loader.qt' => array(0 => 'ts'), 'translation.loader.csv' => array(0 => 'csv'), 'translation.loader.res' => array(0 => 'res'), 'translation.loader.dat' => array(0 => 'dat'), 'translation.loader.ini' => array(0 => 'ini')), array('cache_dir' => (__DIR__.'/translations'), 'debug' => false));
    $instance->setFallbackLocales(array(0 => 'en'));

    $instance->addResource('xlf', (dirname(dirname(dirname(__DIR__))).'/vendor/symfony/symfony/src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf'), 'sv', 'validators');

    // ...

    $instance->addResource('yml', (dirname(dirname(__DIR__)).'/Resources/translations/FOSUserBundle.en.yml'), 'en', 'FOSUserBundle');

    return $instance;
}

It brings something like ~60 ms delay for each page load, and I don't think it is necessary since translations are read from app/cache/prod/translations/catalogue.en.php in production environment.

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