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

Plugin causes performance issues #152

Open
marcingminski opened this issue Sep 3, 2023 · 11 comments
Open

Plugin causes performance issues #152

marcingminski opened this issue Sep 3, 2023 · 11 comments

Comments

@marcingminski
Copy link

Plugin constantly triggers the PHP slow log:

[03-Sep-2023 12:52:19]  [pool www] pid 16838
script_filename = /var/www/html/wordpress/index.php
[0x00007fa1b3813cf0] glob() /var/www/html/wordpress/wp-content/plugins/the-events-calendar-category-colors/src/Category_Colors/Frontend.php:189
[0x00007fa1b3813c00] generate_css() /var/www/html/wordpress/wp-content/plugins/the-events-calendar-category-colors/src/Category_Colors/Frontend.php:159

The line 189 being:

foreach ( glob( "{$css_dir}/teccc*.css" ) as $file ) {

line 189 looks like its part of a function that should have been removed:

        public function generate_css() {
                // TODO: remove after a couple of updates.
                $css_dir = apply_filters( 'teccc_uploads_dir', wp_upload_dir()['basedir'] );
                $css_dir = untrailingslashit( $css_dir );
                foreach ( glob( "{$css_dir}/teccc*.css" ) as $file ) {
                        if ( file_exists( $file ) ) {
                                unlink( $file );
                        }
                }

and line 159 being:

wp_add_inline_style( 'teccc-nofile-stylesheet', $this->generate_css() );

I understand this is because the plugin creates inline CSS every time the page loads.
Is there a way to generate static CSS in the file and embed it in HEAD?

@afragen
Copy link
Collaborator

afragen commented Sep 3, 2023

I've gone back and forth with creating inline vs static CSS and the upside is inline CSS is less problematic on a wider variety of servers, including WordPress VIP hosts.

@marcingminski
Copy link
Author

How about having both options so people can chose what works best for them?

@afragen
Copy link
Collaborator

afragen commented Sep 3, 2023

FWIW generate_css() is cached for about 4 weeks. It shouldn't cause any slowdown after generated.

@marcingminski
Copy link
Author

marcingminski commented Sep 3, 2023

Thanks. I get lots of these in the php slow log. Perhaps they aren’t being cached then? Any way to debug this?

@afragen
Copy link
Collaborator

afragen commented Sep 3, 2023

I'm not familiar with a PHP
Slow log. Where is it generated from?

@marcingminski
Copy link
Author

PHP itself:
request_slowlog_timeout
https://www.php.net/manual/en/install.fpm.configuration.php

@afragen
Copy link
Collaborator

afragen commented Sep 4, 2023

When you say slow, what are the actual times running the function? once, ten times, etc.

@kadamwhite
Copy link

kadamwhite commented Sep 13, 2023

It's a separate issue but I'm also observing that the recent changes to this plugin are causing an update_option call on every page view, which shouldn't be necessary -- I'm looking at this line: https://github.com/the-events-calendar/the-events-calendar-category-colors/blob/develop/src/Category_Colors/Main.php#L247

(get_category_terms is called by load_categories, which is hooked to init, which runs every time WP spins up to serve a request)

It's not a significant performance impact on its own, but I'd think we shouldn't have to update any content on a normal frontend page view.

@afragen I can make a new issue for this if you'd prefer to keep this isolated to the originally described issue

@afragen
Copy link
Collaborator

afragen commented Sep 13, 2023

Might be best to create a new issue.

@kadamwhite
Copy link

@afragen Great, moved that piece to #153

@marcingminski
Copy link
Author

When you say slow, what are the actual times running the function? once, ten times, etc.

sorry missed this - constantly over 2 seconds execution time. I commented out the above lines and the issue (mostly) went away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants