Skip to content

Load symfony container in front - #32719

Merged
mflasquin merged 2 commits into
PrestaShop:developfrom
boherm:#31846-symfony-front-container
Aug 29, 2023
Merged

Load symfony container in front#32719
mflasquin merged 2 commits into
PrestaShop:developfrom
boherm:#31846-symfony-front-container

Conversation

@boherm

@boherm boherm commented May 25, 2023

Copy link
Copy Markdown
Member
Questions Answers
Branch? develop
Description? Add symfony container for front and dotenv files for configurations!
We can enable this experimental feature with new dotenv file!
Type? new feature
Category? FO
BC breaks? yes
Deprecations? no
How to test? Set PS_CONTAINER_V2_FRONT=true in .env file.
Fixed ticket? Fixes #31846
Related PRs
Sponsor company

Notes: You can run tests ui with this PR: PrestaShop/ga.tests.ui.pr#34.

Tests:

Some performances tests:
(with PHP 8.1, no opcache, no docker, with apache & mysql 8.0.33 on MacBook Pro M2 16go Ram)

Page Dev V2 Time I/O wait CPU Memory Network
FO - Homepage 152 ms46.9 ms105 ms6.3 MB205 kB
167 ms44.9 ms122 ms7.5 MB210 kB
148 ms30.1 ms118 ms6.3 MB205 kB
498 ms58.2 ms440 ms12.1 MB210 kB
FO - Product page 224 ms76.2 ms148 ms8.4 MB347 kB
247 ms79.5 ms167 ms9.5 MB352 kB
254 ms91.5 ms162 ms8.4 MB347 kB
616 ms98.4 ms518 ms14.7 MB352 kB
FO - Products listing 431 ms160 ms271 ms10.4 MB650 kB
426 ms162 ms264 ms11.5 MB655 kB
418 ms160 ms258 ms10.4 MB650 kB
801 ms176 ms625 ms18 MB655 kB
FO - Cart
when connected with one product
220 ms73.8 ms146 ms7.5 MB317 kB
318 ms109 ms208 ms14.4 MB339 kB
207 ms64.1 ms143 ms7.5 MB317 kB
638 ms88.2 ms550 ms14.4 MB322 kB
FO - Cart
when connected with 19 products
852 ms312 ms541 ms13.8 MB1270 kB
884 ms330 ms554 ms15.2 MB1270 kB
847 ms313 ms533 ms14.0 MB1270 kB
1370 ms330 ms1040 ms28.5 MB1270 kB
FO - Cart
when connected with 40 products
1740 ms610 ms1130 ms21,6 MB2360 kB
1780 ms627 ms1160 ms22.2 MB2360 kB
1690 ms588 ms1100 ms20.9 MB2360 kB
2480 ms658 ms1820 ms45.9 MB2360 kB

Conclusions about performances tests:

  • This new container can slow down some pages.
    • Front migration can optimize performance in some way.
  • Use one or multiples services within the container v2, don't get slower the front.
  • Use new container with dev mode may slow down PrestaShop in front.

@boherm
boherm requested a review from a team as a code owner May 25, 2023 16:36
@prestonBot prestonBot added develop Branch Feature Type: New Feature labels May 25, 2023
@boherm
boherm marked this pull request as draft May 25, 2023 16:36
@prestonBot prestonBot added the BC break Type: Introduces a backwards-incompatible break label May 25, 2023
@nicosomb

Copy link
Copy Markdown
Contributor

FYI, @FabienPapet opened (and closed) this PR #29997

@boherm
boherm force-pushed the #31846-symfony-front-container branch 4 times, most recently from b2d8220 to bcf3bcd Compare May 31, 2023 12:44
Comment thread classes/Hook.php Outdated
@boherm
boherm force-pushed the #31846-symfony-front-container branch from bcf3bcd to 2611455 Compare May 31, 2023 12:49
@boherm boherm closed this May 31, 2023
@boherm boherm reopened this May 31, 2023
@boherm
boherm force-pushed the #31846-symfony-front-container branch 2 times, most recently from 148aba0 to b58a3ea Compare May 31, 2023 13:53
Comment thread src/Adapter/Presenter/Product/ProductLazyArray.php Outdated
@boherm
boherm force-pushed the #31846-symfony-front-container branch 3 times, most recently from 62a492b to fb55a48 Compare July 6, 2023 15:51
@boherm
boherm marked this pull request as ready for review July 7, 2023 07:22
@boherm
boherm force-pushed the #31846-symfony-front-container branch from fb55a48 to 3ea9881 Compare July 11, 2023 14:49
Comment thread app/AppKernel.php Outdated
Comment on lines +52 to +55
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless

Comment on lines +88 to +89
$container->addCompilerPass(new LoadServicesFromModulesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, self::LOAD_MODULE_SERVICES_PASS_PRIORITY);
$container->addCompilerPass(new LoadServicesFromModulesPass($this->appType), PassConfig::TYPE_BEFORE_OPTIMIZATION, self::LOAD_MODULE_SERVICES_PASS_PRIORITY);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super dangerous. The DI should never know if we are in a frontend or a backend context. This information should come from the request for example, but should not be used inside a compiler pass.

Comment thread .env.dist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this file since we already have .env

Comment thread app/AdminKernel.php Outdated
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);
$this->appType = AppKernel::TYPE_ADMIN;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think appType it's not handy. We should remove it and based the comparison on $kernel::class (which should be either AdminKernel or FrontKernel)

Comment thread app/FrontKernel.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this class used?

@Hlavtox

Hlavtox commented Jul 18, 2023

Copy link
Copy Markdown
Member

FO cart is already extremely to slow, to a point where it's on the edge of usability, we can't offer to have this slowdown :(

Snímek obrazovky 2023-07-18 070844

@boherm

boherm commented Jul 18, 2023

Copy link
Copy Markdown
Member Author

Hi @Hlavtox, yes and it's a big slow.
But, I really don't why, I can't reproduce this time again... Now, I don't have a big time delta like this.

To know what is going on, I want to reinstall a fresh PrestaShop instance and retests some pages like I did.
I wonder if it's a Symfony kernel cache issue that can be really ready after dozen requests.

@tleon tleon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tho I don't think I know the topic enought to aprouve this on my own. Would love to have other inputs

@boherm
boherm force-pushed the #31846-symfony-front-container branch from 6a9d8b7 to 311bc21 Compare August 21, 2023 13:08
@boherm
boherm marked this pull request as ready for review August 22, 2023 07:29
@boherm boherm changed the title [WIP] Load symfony container in front Load symfony container in front Aug 22, 2023
Comment thread composer.json
Comment on lines +1 to +57
services:
_defaults:
public: true

prestashop.core.filter.front_end_object.main:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\MainFilter
autoconfigure: true
arguments:
- cart: '@prestashop.core.filter.front_end_object.cart'
customer: '@prestashop.core.filter.front_end_object.customer'
shop: '@prestashop.core.filter.front_end_object.shop'
configuration: '@prestashop.core.filter.front_end_object.configuration'

prestashop.core.filter.front_end_object.product:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\ProductFilter

prestashop.core.filter.front_end_object.cart:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\CartFilter
arguments:
- '@prestashop.core.filter.front_end_object.product_collection'

prestashop.core.filter.front_end_object.search_result_product:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\SearchResultProductFilter

prestashop.core.filter.front_end_object.customer:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\CustomerFilter

prestashop.core.filter.front_end_object.shop:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\ShopFilter

prestashop.core.filter.front_end_object.configuration:
class: PrestaShop\PrestaShop\Core\Filter\FrontEndObject\ConfigurationFilter

prestashop.core.filter.front_end_object.product_collection:
class: PrestaShop\PrestaShop\Core\Filter\CollectionFilter
calls:
- method: queue
arguments:
- [ '@prestashop.core.filter.front_end_object.product' ]

prestashop.core.filter.front_end_object.search_result_product_collection:
class: PrestaShop\PrestaShop\Core\Filter\CollectionFilter
calls:
- method: queue
arguments:
- [ '@prestashop.core.filter.front_end_object.search_result_product' ]

prestashop.adapter.module.repository.module_repository:
class: 'PrestaShop\PrestaShop\Adapter\Module\Repository\ModuleRepository'
arguments:
- !php/const _PS_ROOT_DIR_
- !php/const _PS_MODULE_DIR_

prestashop.translation.translator_language_loader:
class: PrestaShopBundle\Translation\TranslatorLanguageLoader
arguments:
- '@prestashop.adapter.module.repository.module_repository'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this ADR, can you use FQCN for services names https://github.com/PrestaShop/ADR/blob/master/0019-FQCN-Autowiring.md ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a configuration for legacy services used in front, and I can't really switch to FQCN without some big changes that can introduce some big breaking changes (and if we delete theses alias).
But, I think that can be done in another PR and why not optimize this system too.
What do you think about it?

@boherm
boherm force-pushed the #31846-symfony-front-container branch from 5cdb1e7 to 1369ab7 Compare August 22, 2023 15:56

@matks matks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is OK for me 👍

There's a little comment from @mflasquin I have nothing to add

@Hlavtox

Hlavtox commented Aug 23, 2023

Copy link
Copy Markdown
Member

@matks It cannot be merged if it slows down cart loading 3 times in production mode

@boherm

boherm commented Aug 28, 2023

Copy link
Copy Markdown
Member Author

@Hlavtox, after some new benchmarks with this system, I don't be able to reproduce the loading X3 in production mode.
In fact, I've got in all new tests arround 310ms in cart page with this implementation and in production mode.
(I've update the table in description with new values)

So I think that can be ok to merge seen that this implementation is behind a feature flag.

@M0rgan01 M0rgan01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the performance comparison table :) The changes announce a good thing

@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Aug 29, 2023
@boherm

boherm commented Aug 29, 2023

Copy link
Copy Markdown
Member Author

@aniszr aniszr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @boherm

I tested your PR and it LGTM!
The modifications done on the.env file didn't cause any problems on the FO:heavy_check_mark:

See attached screenshots:
image

image

Thanks!

@aniszr aniszr self-assigned this Aug 29, 2023
@aniszr aniszr added QA ✔️ Status: check done, code approved and removed Waiting for QA Status: action required, waiting for test feedback labels Aug 29, 2023
@prestonBot

Copy link
Copy Markdown
Collaborator

QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge.

@mflasquin

Copy link
Copy Markdown
Contributor

Big thanks to @boherm for this PR !

@mflasquin
mflasquin merged commit bea5f35 into PrestaShop:develop Aug 29, 2023
@matks matks added the Key feature Notable feature to be highlighted label Aug 29, 2023
@matks matks added this to the 9.0.0 milestone Aug 29, 2023
@matks

matks commented Aug 29, 2023

Copy link
Copy Markdown
Contributor

@mflasquin Don't forget the milestone

@mickaelandrieu

mickaelandrieu commented Jun 12, 2024

Copy link
Copy Markdown
Contributor

This was already a feature (see https://github.com/PrestaShop/PrestaShop/blob/develop/classes/container/LegacyCompilerPass.php), you have to tag a service with the tag "front" to make it available in every legacy controller.

What's the difference with this new container ?

An old exemple of integration => https://github.com/friends-of-presta/masterclass/blob/master/config/services.yml#L53

@boherm
boherm deleted the #31846-symfony-front-container branch July 16, 2024 09:34
@kpodemski kpodemski added the Documentation ✔️ Developer documentation is up-to-date label Jul 31, 2024
@PululuK

PululuK commented Feb 11, 2025

Copy link
Copy Markdown
Member

Hummm good point @mickaelandrieu !

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

Labels

BC break Type: Introduces a backwards-incompatible break develop Branch Documentation ✔️ Developer documentation is up-to-date Feature Type: New Feature Key feature Notable feature to be highlighted QA ✔️ Status: check done, code approved

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Spike: Make Symfony Container accessible in Front Office