Sylius: Symfony deprecated Intl::getRegionBundle() causes PHP Fatal error: Allowed memory size...

Created on 3 Sep 2019  路  4Comments  路  Source: Sylius/Sylius

| Q | A
| ---------------- | -----
| Bug report? | no
| Feature request? | no
| BC Break report? | no/yes
| RFC? | no/yes
| Sylius version | 1.5.3

image

When trying to edit a zone with 28 Countries (EU ;-))
Got a blank page and a PHP Fatal error allowed memory size of X exhausted in the log.
I set memory_limit to -1 (no limit)
image

Editing _Sylius\Component\Addressing\Model\Country_ fixed the issue. Do I submit a patch ? on master or 1.5 ?

// Sylius\Component\Addressing\Model\Country
....
// use Symfony\Component\Intl\Intl; removed
use Symfony\Component\Intl\Countries;
...
// return Intl::getRegionBundle()->getCountryName($this->code, $locale); removed
return Countries::getName($this->code, $locale);
Performance

Most helpful comment

Hello !

I spent some time on this exact problem yesterday afternoon.

With a much much bigger zone members list (let's say something called "Rest of the world"), replacing the old Intl::getXXXBundle() API reduces drastically the time used, but then it's still a bit too much time consuming (went from 30s timeout to a 15s loading time on a 150+ Country members zone).

The problem is, when your members are Country type for example :

  • Each CountryCodeChoiceType has a list of Country elements as choices
  • Each displayed value is then rendered by using Country->getName() (using the choice_value type option), which then subsequently calls the Symfony Intl components
  • Those choices are then sorted using usort which, for the comparison, calls... Country->getName()
  • Multiply all this process by something like 150 members on a single page...

Somehow all those forms shouldn't access to the Intl component data a trillion time, it should be passed by parent form (in those cases, the country list is not gonna change from one member to another).

I fear this kind of thing could happen with every other Intl components (locales, currencies, etc...) but I don't think Sylius has another page which can potentially gather so many items of those types.

Any thoughts on this on the Sylius side ? :D

All 4 comments

Hello !

I spent some time on this exact problem yesterday afternoon.

With a much much bigger zone members list (let's say something called "Rest of the world"), replacing the old Intl::getXXXBundle() API reduces drastically the time used, but then it's still a bit too much time consuming (went from 30s timeout to a 15s loading time on a 150+ Country members zone).

The problem is, when your members are Country type for example :

  • Each CountryCodeChoiceType has a list of Country elements as choices
  • Each displayed value is then rendered by using Country->getName() (using the choice_value type option), which then subsequently calls the Symfony Intl components
  • Those choices are then sorted using usort which, for the comparison, calls... Country->getName()
  • Multiply all this process by something like 150 members on a single page...

Somehow all those forms shouldn't access to the Intl component data a trillion time, it should be passed by parent form (in those cases, the country list is not gonna change from one member to another).

I fear this kind of thing could happen with every other Intl components (locales, currencies, etc...) but I don't think Sylius has another page which can potentially gather so many items of those types.

Any thoughts on this on the Sylius side ? :D

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@pamil @lchrusciel This issue was fixed in master/1.8 with #10565.

hey @stloyd, thanks for picking it up!

Was this page helpful?
0 / 5 - 0 ratings