This is a bit of an odd request I realize, so bear with me for a second:
Motivation
When used with a large number of beans (say creating those beans with use on an entityreference field), the _block_rehash function becomes a huge performance problem in an unpatched block module. This issue references the problem with 5000 blocks, and patches the block table query in order to make the query take much less time.
There are still some related issues around that, as bean_load_all_beans() can take a significant amount of time, and in certain entityreference situations (like using the Paragraphs module to provide the reference), _block_rehash could be called several times in a given editorial page load (28 times observed in our case). Every 3 of those the static cache would be cleared and bean_load_all_beans() would occur again.
In order to increase performance, we realized that we were not actually using beans as ...well.... blocks. We were only using beans as a generic entity which already had some pretty good integrations into other things (IEF, Panelizer, etc), and not placing them as blocks on various block-system controlled pages.
"Solution"
So, we decided to break the block table integration into a sub-module, and enable that module by default in an update hook (though I don't believe I added anything to turn it on by default on bean module install). This moves I think everything related to the core block table into bean_block, and adds an additional hook to facilitate the cache clearing if the module is enabled.
Footnote
I don't actually expect that this patch is going to be approved, but I figured it's useful to put it up here for review in case someone else has a similar use-case.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 2577095_13.patch | 11.46 KB | mile23 |
| #10 | bean-bean_block_module-2577095-10.patch | 716 bytes | damontgomery |
| #8 | bean-bean_block_module-2577095-7.patch | 11.87 KB | mr-potrox |
| #2 | bean-bean_block_module-2577095-1.patch | 9.92 KB | cthos |
Comments
Comment #2
cthos commentedAnd the patch in question.
Comment #3
cthos commentedComment #5
danepowell commentedJust to weigh in with some "combat reports" after applying this patch... on a site with about 10,000 Beans, disabling block integration brought average memory usage down from 200MB+ to a much more reasonable 20-30MB, and page execution times down from >60s to <1s.
The problem is that the core Block system is just not performant at scale, and was never designed to handle the number of blocks that Bean empowers users to create. And a lot of processes can trigger a block rehash, including Context reactions, Panels/Panelizer, or (obviously) saving Beans or nodes with Beans attached.
I would actually go further than this patch and add a specific warning that the block integration should not be enabled on sites with more than a few hundred Beans.
Comment #6
cthos commentedNot sure why test runner exploded, all those fails appear to be related to " Call to undefined function bean_permission()" in each of the setUp calls, which I didn't touch.
Comment #7
mr-potrox commentedRestrict the bean types to be integrated to the Drupal block system.
Comment #8
mr-potrox commentedComment #9
mr-potrox commentedwrong category
Comment #10
damontgomery commentedThis new patch works with multiple hook_bean_block_override_register functions. Apply over 7_0 patch.
Comment #11
damontgomery commentedThe previous patch, 10, goes on top of 7_0.
Comment #12
mile23None of 7, 8, or 10 apply to current 7.x-1.x.
Comment #13
mile23Rerolled #8 and #10 together.
Comment #14
mile23