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.

If a bug, provide steps to reproduce it from a clean install.

Comments

berdir created an issue.

jsacksick’s picture

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.

Are you sure about that?
Did you perform another test after applying the changes from the MR?

berdir’s picture

"the case I'm testing" is the crucial bit of that sentence, and it wasn't very clear.

The case I'm testing is an anonymous user, because the storage is now only requested when actually needed. That means: (anonymous OR authenticated users with a cache hit) AND empty card. These no longer need to load the storage, and with that, don't load the refresh service.

But it's still happening on cache misses for authenticated users and all users with a cart where additional optimization is possible, how much I haven't really looked into and is currently not my focus.