Performance: Multiple Blocks vs Stacks

Permalink
I was wondering if anyone can help me figure out what the performance difference is between copying a block and using it multiple times throughout a site (ie a "back to top" link) versus creating a stack and placing that multiple times throughout a site.

Is there a difference here?

jpcharrier
 
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
Stacks are more efficient for your database. They're also useful for global areas.

Stacks allow you to display the same block many times across your site, and so this means less queries to the database, therefore making the site a bit faster.

Copying blocks creates new instance of that block, which means more data being stored in the database.

If you want to have an efficient site, follow the "less is more" rule and use global areas and stacks.
jpcharrier replied on at Permalink Reply
jpcharrier
Thank you! I was hoping that would be the answer. We have a large section of our site which informative (basically a giant how-to) section where the pages often get very long so we break this up by using 'back to top' links which is a basic html block and custom template. But I wasnt sure if copying and either leaving it as a copied block, or copying and creating a new instance, or using a stack was the most efficient way of doing it.

Thanks for your response :)
JohntheFish replied on at Permalink Reply
JohntheFish
The number of blocks or stacks in the database makes very little difference to database speeds unless the whole thing starts to get extremely big. Even then, database speed is more a server issue than a size issue.

If you ignore caching, the difference between a copied block and a stack with a block in it is:

* Block:
Area loads block A

* Stack:
Area loads stack X
Stack X loads block A

Stacks are not fully cached by the block cache, so if block caching is enabled and the block is fully cached:

* Block:
Area loads block A from cache

* Stack:
Area loads stack X
Stack X loads block A from cache

There are ways round this.

Easiest is to enable the page cache and force page caching for the entire page (as long as it gives no problems for any blocks within it)

My Universal Content Puller block can cache the content of a rendered stack within UCP's own cache, but then UCP blocks themselves are not cached, so unless the stack is very big and slow, the difference is not important.

In your particular case, if you had one 'back to top block' and in the block design positioned that fixed in the window ( seehttp://www.w3schools.com/css/css_positioning.asp... - fixed positioning ), then the one back to top link would float over the page and you wouldn't need all the copies. (there is an addon that does something like that)

Or you could render the block once and then clone it about the page using jQuery.