• Running on WP 3.7
    TLDR: 1 :print_script_block_data is generating 324MB extra peak memory in my setup of 338 categories.

    if i list wp_print_footer_scripts ‘s hooked functions, I get the following:

    -1 Jetpack:implode_frontend_css
    1 :print_script_block_data
    5 :localize_printed_scripts
    9 CJTBlocksCouplingController:linkFooterStyleSheets
    10 _wp_footer_scripts
    10 QM_Collector_Assets_Scripts:action_print_footer_scripts
    10 QM_Collector_Assets_Styles:action_print_footer_scripts
    10 log_memory_usage

    If I tap in at wp_print_footer_scripts with priority -2, 0, 2, 6, 9 and record memory_get_usage and memory_get_peak_usage this is what I get:

    <br />wppfs @ -2 memory_get_usage=28MB
    <br />wppfs @ -2 memory_get_peak_usage=28MB
    <br />wppfs @ 0 memory_get_usage=28MB
    <br />wppfs @ 0 memory_get_peak_usage=28MB
    <br />wppfs @ 2 memory_get_usage=34MB
    <br />wppfs @ 2 memory_get_peak_usage=358MB
    <br />wppfs @ 6 memory_get_usage=34MB
    <br />wppfs @ 6 memory_get_peak_usage=358MB
    <br />wppfs @ 9 memory_get_usage=34MB
    <br />wppfs @ 9 memory_get_peak_usage=358MB

    Therefore this means that 1 :print_script_block_data is generating 324MB extra peak memory.

    Query monitor reports 177 queries in total being done when this action is active.

    Removing this action drops the extra peak memory, here is a report of memory usage in wp_print_footer_scripts at priority -2, 0, 2, 6, 9 after removal:

    <br />wppfs @ -2 memory_get_usage=33MB
    <br />wppfs @ -2 memory_get_peak_usage=33MB
    <br />wppfs @ 0 memory_get_usage=33MB
    <br />wppfs @ 0 memory_get_peak_usage=33MB
    <br />wppfs @ 2 memory_get_usage=33MB
    <br />wppfs @ 2 memory_get_peak_usage=33MB
    <br />wppfs @ 6 memory_get_usage=33MB
    <br />wppfs @ 6 memory_get_peak_usage=33MB
    <br />wppfs @ 9 memory_get_usage=33MB
    <br />wppfs @ 9 memory_get_peak_usage=33MB

    Site has 338 categories in wc_product_block_data

    The fix was

    add_action( 'wp_head', 'fix_memory_leak' );
    function fix_memory_leak(){
        remove_all_actions('wp_print_footer_scripts', 1); 
        remove_all_actions('admin_print_footer_scripts', 1);
    }

    However this might be removing additional actions hooked at priority 1. I wasn’t able to remove the action via it’s name.

    • This topic was modified 6 years, 8 months ago by flo_sb.
    • This topic was modified 6 years, 8 months ago by flo_sb.
    • This topic was modified 6 years, 8 months ago by flo_sb.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter flo_sb

    (@flo_sb)

    The above code snippet does not work for wp-admin, as there is no wp_head action in wp-admin.

    This’ll work for both.

    add_action('wp_head', 'fix_memory_leak'); //runs on frontend
    add_action('admin_enqueue_scripts', 'fix_memory_leak'); //runs on wp-admin
    
    function fix_memory_leak(){
        remove_all_actions('wp_print_footer_scripts', 1);
        remove_all_actions('admin_print_footer_scripts', 1);
    }

    Also, could you please let me know how I can remove woocommerce-blocks entirely?

    Thanks for the temporary fix. I have a store with 680000+ products and 200+ categories and this footer_scripts really increased loading time by almost 3 times.

    Something should be done about it.

    Thank you for fix. It literally reduced query on each page. On each page it was doing _pad_term_counts which was returning 18k rows and slowing down page. I found through query monitor that it runs in wp_footer (wp_print_footer_scripts) script. This code helps to remove it

    • This reply was modified 6 years, 7 months ago by kkataria.
    Vikram S.

    (@jodhavishalsingh)

    Hi, Use this in functions.php

    add_action('wp_footer','wooexperts_remove_block_data',0);
    add_action('admin_enqueue_scripts','wooexperts_remove_block_data',0);
    function wooexperts_remove_block_data(){ 
        remove_filter('wp_print_footer_scripts',array('Automattic\WooCommerce\Blocks\Assets','print_script_block_data'),1);
        remove_filter('admin_print_footer_scripts',array('Automattic\WooCommerce\Blocks\Assets','print_script_block_data'),1);
    }
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘1 :print_script_block_data in wp_print_footer_scripts destroys memory usage’ is closed to new replies.