stellarwp / kadence-blocks

Advanced Page Building Blocks for Gutenberg. Create custom column layouts, backgrounds, dual buttons, icons etc.
282 stars 82 forks source link

Performance of Kadence_Blocks_Svg_Render->render_icons_dynamically #598

Open benniledl opened 3 weeks ago

benniledl commented 3 weeks ago

Hello, I have a Problem that Kadence really slows down my site quite a bit (about 400 ms). I have measured it and found that the slowest function is render_icons_dynamically, this one function alone takes up about 140ms on a page load, so about 35% of the overall time.

I just wanted to ask if you could take a look over this function and see if any performance improvements can be made on it. grafik

benniledl commented 3 weeks ago

Here the measurement on a page where I use quite a few more Icons: grafik

kadencewp commented 3 weeks ago

Hey, this function would query custom icons if there are any, which could require requests to the database. On initial hit, this could take milliseconds like you show, but once cached, it should be instant. Are you not seeing this cached? are you not using any caching on your site?

benniledl commented 3 weeks ago

Hey, I am using custom uploaded svg icons. The slowest database query is not even 1ms long and this function runs 300ms so this is not a database issue. I will be using a page cache once I go online but I want to solve this problem not treat it's symptoms.

I think this function is slow because of string manipulation or something like that. Can you check how a test site of yours slows down the more custom icons you are using?

kadencewp commented 3 weeks ago

How many custom icons are you using? Are you using a bunch of individual or a set?

kadencewp commented 3 weeks ago

@oakesjosh can you put this on your list to explore some options

benniledl commented 3 weeks ago

It's from one library set but each one is an individual svg file that I upload individually. Rough guess 70 icons on the whole page but at least 50 of them is the same icon.

oakesjosh commented 2 weeks ago

Hello @benniledl

I've just pushed some caching for our icon parsing, which improves performance with repeated use of the same icons. You should see a noticeable improvement with this change; if not, feel free to reach out, and we can take another look.

benniledl commented 2 weeks ago

Hi @oakesjosh thanks for that! I have tested your changes but sadly they don't change anything. The render_icons_dynamically function still runs about 300ms in total on a page load. Do you want me to make some changes that could output some debug information or something?

oakesjosh commented 2 weeks ago

@benniledl Are you seeing the same slowdown in real world performance? I don't have the pro version of Code profiler, but in my tests, code profiler is reporting 4 or 5 times slower than the actual performance on the front end.

You're welcome to debug, or if it doesn't have any sensitive information, I'd be happy to test on an export of your site. I will take a second look on my end.