Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Injection is very slow #2745

Open
casperh123 opened this issue Dec 25, 2024 · 5 comments
Open

Dependency Injection is very slow #2745

casperh123 opened this issue Dec 25, 2024 · 5 comments
Labels
category: performance The issue/PR is related to performance. needs investigation

Comments

@casperh123
Copy link

casperh123 commented Dec 25, 2024

Describe the bug:

The dependency injection container operations in Google Listings and Ads are consuming are taking a long time to execute causing performance degradation.

Steps to reproduce:

  1. Observe New Relic APM while Google Listings and Ads is active.
  2. Observe container resolution times:
    • Definition::resolveNew: 28.24ms (4.38%)
    • Container::get: 34.13ms (5.29%)

Image

This is especially bad on Admin pages, where we have the following trace:

Image

Expected behavior:

Container operations should have minimal performance impact on plugin execution.

Actual behavior:

Container resolution is taking ~10-50% of execution time, primarily in:

#AutomatticWooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition::resolveNew
#AutomatticWooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container::get

Additional details:

System Status Report
### WordPress Environment ###

WordPress address (URL): [Redacted]
Site address (URL): [Redacted]
WC Version: 9.5.1
Legacy REST API Package Version: The Legacy REST API plugin is not installed on this site.
Action Scheduler Version: ✔ 3.8.2
Log Directory Writable: ✔
WP Version: 6.7.1
WP Multisite: –
WP Memory Limit: 128 MB
WP Debug Mode: –
WP Cron: ✔
Language: da_DK
External object cache: ✔

### Server Environment ###

Server Info: nginx/1.25.5
PHP Version: 8.3.13
PHP Post Max Size: 128 MB
PHP Time Limit: 300
PHP Max Input Vars: 10000
cURL Version: 7.68.0
OpenSSL/1.1.1f

SUHOSIN Installed: –
MySQL Version: 10.11.5-MariaDB-1:10.11.5+maria~ubu2004
Max Upload Size: 128 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

### Post Type Counts ###

acf-field: 1
acf-field-group: 1
adt_product_feed: 2
attachment: 6997
b2bking_custom_field: 7
b2bking_custom_role: 2
b2bking_group: 1
blocks: 121
custom_css: 1
nav_menu_item: 21
oembed_cache: 3
page: 20
post: 1
product: 1488
product_variation: 53
revision: 1248
shop_order: 6139
ux_template: 7
wcs_ruleset: 4
wp_global_styles: 1
wpcode: 1

### Security ###

Secure connection (HTTPS): ✔
Hide errors from visitors: ✔

### Active Plugins (36) ###

FiboSearch - AJAX Search for WooCommerce (Pro): by FiboSearch Team – 1.28.0
atec Cache APCu: by Chris Ahrweiler – 2.1.19
The SEO Framework: by The SEO Framework Team – 5.1.2
PublishPress Capabilities Pro: by PublishPress – 2.13.0
Clypper BIN Numbers: by Clypper von H – 1.0.0
Clypper Bundle Price Calculator: by Clypper von H – 1.1.1
Clypper Custom Checkout: by Clypper von H – 1.2.8
Clypper Leasing: by Clypper von H – 1.0.2
Clypper Show Attributes: by Clypper von H – 1.7.1
Clypper Stock Keeping Units: by Clypper von H – 1.0.0
Clypper Totalvægt: by Clypper von H – 1.0.0
Complianz | GDPR/CCPA Cookie Consent: by Really Simple Plugins – 7.1.5
Disable Bloat for WordPress & WooCommerce PRO: by Disable Bloat – 3.4.8
Duplicate Page: by mndpsingh287 – 4.5.4
Fast Velocity Minify: by Raul Peixoto – 3.4.1
Google for WooCommerce: by WooCommerce – 2.9.3
Hotjar: by Hotjar – 1.0.16
Perfect Brands WooCommerce: by QuadLayers – 3.4.7
ShortPixel Image Optimizer: by ShortPixel - Convert WebP/AVIF & Optimize Images – 6.0.4
Simple Basic Contact Form: by WPKube – 20240511
Smart Send Shipping for WooCommerce: by Smart Send ApS – 8.1.1
Speculative Loading: by WordPress Performance Team – 1.3.1
Woolab: by Woolab A/S – 3.5.7
Tax Preference: by Clypper Technology – 1.0.0
Trustpilot-reviews: by Trustpilot – 2.5.925
WooCommerce Conditional Shipping Pro: by Lauri Karisola / WP Trio – 2.7.4
Product Feed PRO for WooCommerce: by AdTribes.io – 13.4.0
Product Filter by WBW: by woobewoo – 2.7.6
WooCommerce.com Update Manager: by Automattic – 1.0.3
PDF Invoices & Packing Slips for WooCommerce: by WP Overnight – 3.9.2
Pixel Manager Pro for WooCommerce: by SweetCode – 1.45.0
WooCommerce Product Bundles: by WooCommerce – 6.22.3 (update to version 8.2.2 is available)
WooCommerce Quickpay: by Perfect Solution – 7.3.4
WooCommerce: by Automattic – 9.5.1
WBW Product Filter PRO: by WBW – 2.3.7
SMS for WooCommerce: by zorem – 2.1.0

### Inactive Plugins (3) ###

Facebook for WooCommerce: by Facebook – 3.3.1
Loco Translate: by Tim Whitlock – 2.6.14
Query Monitor: by John Blackbourn – 3.17.0

### Dropin Plugins () ###

advanced-cache.php: advanced-cache.php
object-cache.php: atec APCu-Object-Cache

### Must Use Plugins (2) ###

disable-woocommerce-block.php: by  –
Kinsta Must-use Plugins: by Kinsta Team – 3.1.1

### Settings ###

Legacy API Enabled: –
Force SSL: ✔
Currency: DKK (kr.)
Currency Position: right_space
Thousand Separator: .
Decimal Separator: ,
Number of Decimals: 2
Taxonomies: Product Types: bundle (bundle)
external (external)
grouped (grouped)
simple (simple)
variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)

Connected to WooCommerce.com: ✔
Enforce Approved Product Download Directories: –
HPOS feature enabled: –
Order datastore: WC_Order_Data_Store_CPT
HPOS data sync enabled: ✔

### Logging ###

Enabled: ✔
Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2
Retention period: 30 days
Level threshold: –
Log directory size: 632 KB

### WC Pages ###

Shop base: #8 - /shop/
Cart: #56 - /cart/ -  Contains the [woocommerce_cart] shortcode
Checkout: #55 - /checkout/ -  Contains the [woocommerce_checkout] shortcode
My account: #54 - /my-account/
Terms and conditions: #12 - /refundering_returvarer/

### Theme ###

Name: Flatsome Child
Version: 3.3
Author URL: 
Child Theme: ✔
Parent Theme Name: Flatsome
Parent Theme Version: 3.19.8
Parent Theme Author URL: https://uxthemes.com
Theme type: Classic theme
WooCommerce Support: ✔

### Templates ###

Overrides: flatsome/woocommerce/archive-product.php
flatsome/woocommerce/cart/cart-empty.php
flatsome/woocommerce/cart/cart-shipping.php
flatsome/woocommerce/cart/cart.php
flatsome/woocommerce/cart/mini-cart.php
flatsome/woocommerce/checkout/form-checkout.php
flatsome/woocommerce/checkout/form-coupon.php
flatsome/woocommerce/checkout/order-received.php
flatsome/woocommerce/checkout/terms.php
flatsome/woocommerce/checkout/thankyou.php
flatsome/woocommerce/content-product-cat.php
flatsome/woocommerce/content-product.php
flatsome/woocommerce/content-single-product.php
flatsome/woocommerce/content-widget-product.php
flatsome/woocommerce/global/breadcrumb.php
flatsome/woocommerce/global/quantity-input.php
flatsome/woocommerce/global/wrapper-end.php
flatsome/woocommerce/global/wrapper-start.php
flatsome/woocommerce/loop/header.php
flatsome/woocommerce/loop/loop-end.php
flatsome/woocommerce/loop/loop-start.php
flatsome/woocommerce/loop/pagination.php
flatsome/woocommerce/loop/rating.php
flatsome/woocommerce/loop/result-count.php
flatsome/woocommerce/loop/sale-flash.php
flatsome/woocommerce/myaccount/form-login.php
flatsome/woocommerce/myaccount/navigation.php
flatsome/woocommerce/notices/error.php
flatsome/woocommerce/notices/notice.php
flatsome/woocommerce/notices/success.php
flatsome/woocommerce/product-searchform.php
flatsome/woocommerce/single-product/photoswipe.php
flatsome/woocommerce/single-product/price.php
flatsome/woocommerce/single-product/product-image.php
flatsome/woocommerce/single-product/product-thumbnails.php
flatsome/woocommerce/single-product/rating.php
flatsome/woocommerce/single-product/related.php
flatsome/woocommerce/single-product/review.php
flatsome/woocommerce/single-product/sale-flash.php
flatsome/woocommerce/single-product/share.php
flatsome/woocommerce/single-product/short-description.php
flatsome/woocommerce/single-product/tabs/tabs.php
flatsome/woocommerce/single-product/title.php
flatsome/woocommerce/single-product/up-sells.php
flatsome/woocommerce/single-product-reviews.php
flatsome/woocommerce/single-product.php


### Product Bundles ###

Database Version: 6.22.31
Loopback Test: ✔
Template Overrides: –

### Admin ###

Enabled Features: activity-panels
analytics
product-block-editor
coupons
core-profiler
customize-store
customer-effort-score-tracks
import-products-task
experimental-fashion-sample-products
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
mobile-app-banner
onboarding
onboarding-tasks
pattern-toolkit-full-composability
product-custom-fields
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
printful
shipping-label-banner
subscriptions
store-alerts
transient-notices
woo-mobile-welcome
wc-pay-promotion
wc-pay-welcome-page
launch-your-store

Disabled Features: product-data-views
experimental-blocks
coming-soon-newsletter-template
minified-js
product-pre-publish-modal
settings
async-product-editor-category-field
product-editor-template-system
blueprint
reactify-classic-payments-settings
use-wp-horizon
add-to-cart-with-options-stepper-layout

Daily Cron: ✔ Next scheduled: 2024-12-26 09:12:50 +01:00
Options: ✔
Notes: 67
Onboarding: completed

### Action Scheduler ###

Complete: 4,108
Oldest: 2024-11-24 13:55:36 +0100
Newest: 2024-12-25 13:20:37 +0100

Failed: 131
Oldest: 2023-03-29 10:23:48 +0200
Newest: 2024-12-21 23:08:40 +0100

Pending: 9
Oldest: 2024-12-25 14:20:37 +0100
Newest: 2025-01-13 13:19:36 +0100


### Status report information ###

Generated at: 2024-12-25 13:55:08 +01:00
@tomalec tomalec added category: performance The issue/PR is related to performance. needs investigation labels Dec 29, 2024
@jconroy
Copy link
Member

jconroy commented Dec 30, 2024

Thanks @casperh123 - any chance you can drill in a little more? It might be pulling in some excess code from the Google packages or there might be a rogue external request we need to correct

Any additional information you can pull from your New Relic instance would be appreciated as there will be a level of uniqueness to your setup too.

Also confirming, the store you are optimizing has roughly

products: 1488
orders: 6139

And it doesn't have HPOS enabled?

@mikkamp
Copy link
Contributor

mikkamp commented Dec 30, 2024

Also just wanted to cross link the issue here which has some additional discussion on the same topic: #1250

One of the suggestions was to check the type of requests and only load the services which are needed for each type of request. That will need some further investigation/testing to make sure that doesn't introduce additional conflicts.

@casperh123
Copy link
Author

casperh123 commented Dec 30, 2024

Heres some more detailed screenshots of some traces. They are too long to capture in a single screenshot, so they span multiple screenshots.

The site does not have HPOS enabled at the moment. We are investigating wether or not some old dependencies are compatible.

Trace #1 - Page: taxonomy-product-cat, function: GoogleListingsAndAdsPlugin::maybe_register_services

Part 1

Image

Part 2

Image

Part 3

Image

Trace 2

Part 1 - Page: single-product

Image

Part 2

Image

Part 3

Image

In the observed traces related to Dependency Injection, i havent seen any external calls. Just App Code.

Let me know if there are specific data from our New Relic instance, that you would be interrested in.

@casperh123
Copy link
Author

I'm not sure if it is related, but Core WooCommerce also had performance issues with their Dependency Injection library.
Heres the Pull Request that fixes their issue:
woocommerce/woocommerce#52296

@mikkamp
Copy link
Contributor

mikkamp commented Jan 2, 2025

Thanks @casperh123 for providing the additional screenshots. While I do agree that the Google for WooCommerce extension can improve it's loading of dependent classes (or at least the quantity depending on the request).

However, what we see from those details isn't fully portraying the same picture as was described in the initial issue.

For example we can see that for the frontend request it's spending 34.13ms in the function Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container::get being called 5 times. But based on the hierarchy we can see it calling Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition::resolveNew as part of that time. So we can determine that part of that 34.13ms is spent within the resolveNew function (28.24ms in this case). But we can't add the times together.

For the same reason you can find do_action or other WP hook/filter functions very high in the list, but that isn't reflective of which plugin might be hooking into those filters and taking up time. What I'm trying to highlight here is that we need to do some further drilling down into where we can see performance gains, but many of those gains might not be linked directly to Dependency Injection. So this isn't indicative enough to state that the "Dependency Injection is very slow", or that it should be replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: performance The issue/PR is related to performance. needs investigation
Projects
None yet
Development

No branches or pull requests

4 participants