Hi tictag,
Yes, on each page load, the database is queried to fetch the active snippets. However, this is just one query out of the many that are run with every page load simply as a part of having WordPress installed.
The actual performance impact that this query will have depends on how performant your server is, and how many snippets you have, along with how many lines of code need to be fetched. I imagine that on most sites this is pretty negligible – on my site, it takes around 0.0003 seconds.
If you want to check on your own site, I recommend the Query Monitor plugin – once installed, you can open the panel, go to the Queries section, and look how long it took to run the query beginning with SELECT FROM wp_snippets
(where wp_
is your WordPress database table prefix).
0.0003 seconds certainly sounds reasonable :-), though I do wonder how many snippets were included in your test. I will have around 100 if I implement this plugin. How much of a performance delay would 100 snippets create on each page load? 100 x 0.0003 seconds?
I doubt it would scale linearly like that – there would be a fair amount of overhead just for sending a query and getting back a result, irrespective of the sort of query and data.
I had around 10 snippets active when I checked how long the query took. I can test with 100 if you’re still curious, but it’s probably going to be more reliable if you install Query Monitor and test on your own server, as that will likely have more of an impact than the number of snippets.
Happy to install Query Monitor, I’ve used it in the past. I suppose I don’t want to go through the process of transferring all my custom code to Code Snippets (build/test etc) if I then end up un-installing it due to a performance issue. That’s really the point of this query.
It would certainly help me to decide whether the investment in time is warranted. May I take you up on your offer?
My website pages currently return in about 1.1 seconds, and there’s more that can be done to improve that. So there’s a pretty reasonable ‘visitor experience’ as they click around the site. If installing Code Snippet added, say, more than 0.5 seconds, that would be unacceptable because the user experience would suffer, just because of the ‘convenience’ of having custom code delivered in a more intuitive way i.e. to help me. If delivering 100 snippets impacted less than, say, 0.1 seconds, then I would install it tomorrow!
I suggest you look at Redis as an object cache for WordPress, and WP Rocket as a front-end cache which will create static HTML files so your webserver will deliver those instead of going the expensive Apache/MySQL dynamic route for each request.
-
This reply was modified 3 years, 8 months ago by ablears.