justcoded / just-responsive-images

WordPress Plugin to support better responsive images with <picture> tag, backgrounds, retina support etc.
48 stars 8 forks source link

Performance issues when using rwd_attachment_background #30

Closed therajumandapati closed 5 years ago

therajumandapati commented 5 years ago

The function rwd_attachment_background takes more than 2s to load for some images and it's faster for some images.

We're using a timing function to calculate the performance, the setup looks like this:

function rwd_attachment_background( $selector, $attachment = null, $size = 'thumbnail' ) {
    $jri_time_start = microtime(true);
    $rwd_image = new RwdImage( $attachment );
    $jri_time_end = microtime(true);

    $class_exec_time = $jri_time_end - $jri_time_start;

    //execution time of the script
    $jri_time_start_2 = microtime(true);
    echo $rwd_image->background( $selector, $size );
    $jri_time_end_2 = microtime(true);
    $bg_exec_time = $jri_time_end_2 - $jri_time_start_2;
    echo '<b>'.$selector.' Class Time:</b> '.$class_exec_time.' Secs, <b>Bg Time:</b> '.$bg_exec_time.' Secs';
}

The responses are over 2s for some images. Following are some examples:

Can you help us figure out why some images are taking a long time to load while some load faster even when using the same image size?

therajumandapati commented 5 years ago

@aprokopenko Any help here would be greatly appreciated 😃

aprokopenko commented 5 years ago

Hi,

Please post your configuration array for the size you get 2 seconds delay. Also, do you have it on each page load? or only on the first time (on the first time it's normal actually)?

therajumandapati commented 5 years ago

@aprokopenko Here you go.

'hero-banner 2x' => array(
        'desktop' => array(
            array(2304, 1116, true),
            'picture' => '<source srcset="{src}"  media="(min-width: 1441px)">',
            'bg' => '@media (min-width:1441px)',
            'bg_retina' => '@media (min-width:1441px) and {dpr}, (min-width:1441px) and {min_res}',
            'srcset' => '{w}w',
            'sizes' => '(min-width: 1441px) {w}px',
        ),
        'laptop' => array(
            array(1728, 936, true),
            'picture' => '<source srcset="{src}" media="(min-width: 769px)">',
            'bg' => '@media (min-width: 769px)',
            'bg_retina' => '@media (min-width: 769px) and {dpr}, (min-width: 769px) and {min_res}',
            'srcset' => '{w}w',
            'sizes' => '(min-width: 769px) {w}px',
        ),
        'tablet' => array(
            array(922, 936, true),
            'picture' => '<source srcset="{src}" media="(min-width: 361px)">',
            'bg' => '@media (min-width: 361px)',
            'bg_retina' => '@media (min-width: 361px) and {dpr}, (min-width: 361px) and {min_res}',
            'srcset' => '{w}w',
            'sizes' => '(min-width: 361px) {w}px',
        ),
        'mobile' => array(
            array(432, 432, true),
            'picture' => '<img src="{single-src}" srcset="{src}" alt="{alt}">',
            'bg' => '',
            'bg_retina' => '@media {dpr}, {min_res}',
            'srcset' => '{w}w',
            'sizes' => '{w}px',
        )
    )

It happens on each page load.

aprokopenko commented 5 years ago

It's really weird, it should take a cropped image and do not generate it again, so it should be pretty fast. How big is your postmeta table? (how many rows)

therajumandapati commented 5 years ago

wp_postmeta has 965 rows

aprokopenko commented 5 years ago

Then need to debug RwdImage class itself (background() ) method to find out what's wrong. It's hard to guess.

therajumandapati commented 5 years ago

How can I help you debug?

aprokopenko commented 5 years ago

If it's okay - write me an email with credentials to your server, url and admin credentials and I will take a look next week. (Tomorrow I will be to busy)

aprokopenko commented 5 years ago

With access to your server, I found an issue - for retina sizes it always runs a resize again, if the original image was smaller than the required retina size.

This is fixed in 1.6.4!

therajumandapati commented 5 years ago

Thank you @aprokopenko