Describe your bug or feature request.
I'm working on reducing the number of services and classes that are loaded on basically every request. A big culprit for that is commerce, even though for the scenario I'm testing, commerce doesn't need to do much, or at least far less than it currently does.
I'm debugging this with some file_put_contents() in the Container as services are instantiated, that gives me this:
- cache_context.cart
- - commerce_cart.cart_provider
- - - commerce_store.current_store
- - - - commerce_store.chain_store_resolver
- - - - - commerce_order.order_store_resolver
- - - - - commerce_store.default_store_resolver
- - - commerce_cart.cart_session
- commerce_order.order_refresh
- - commerce_price.chain_price_resolver
- - - commerce_price.default_price_resolver
- - commerce_promotion.promotion_order_processor
- - commerce_payment.order_processor
- - - commerce_payment.order_updater
- - commerce_order.availability_order_processor
- - - commerce_order.availability_manager
- - - - CUSTOM.availability_checker
- - commerce_shipping.early_order_processor
- - - commerce_shipping.order_manager
- - - - commerce_shipping.packer_manager
- - - - - commerce_shipping.default_packer
- - - - - commerce_shipping.admin_packer
- - - commerce_shipping.shipment_manager
- - - - logger.channel.commerce_shipping
- - commerce_tax.tax_order_processor
- - - commerce_price.rounder
- - - commerce_tax.store_tax
- - - - commerce_tax.chain_tax_rate_resolver
- - - - - commerce_tax.default_tax_rate_resolver
- - commerce_shipping.late_order_processor
This is an anonymous request to the frontpage, no session/cart. A big culprit is commerce_order.order_refresh and it's many dependency. This is created in the order storage, which is initialized in \Drupal\commerce_cart\CartProvider::loadCartData.
It results in a slight repetition, but the storage isn't needed for anonymous users without session as it won't run a query then and won't have cart ids.
This can possible be moved into #3584409: Cache result of query in loadCartData then for the case I'm testing, most of that will vanish.
But I'm creating this anyway as it might be useful to improve this further for authenticated users. The order refresh service could use service closures to avoid instantiating processors when the order doesn't need to be refreshed, the cache contexts/cart provider themself could possible also use more service closures.
Comments