Advanced Plugin Optimization System
1 Attachment(s)
New! Attached prototype files to get you started :) Also updated to address a bug
This is a method you should use to optimize the way your plugins work in your hacks! Background After writing hacks with many many plugins, you run into a couple problems...
Every coder should be familiar with this clever optimization technique, it is even in the vBulletin manual: https://vborg.vbsupport.ru/showthrea...ghlight=plugin Basically: move plugins to the file system! There is also a "Plugin Accelerator" which does that too. However, now you have a couple dozen FILES to watch after, and it still is too messy for my taste. My next step was to put them all into a single file that gets included in every plugin, but the plugin also has to set some global indicator before including, because the vB system doesn't declare what plugin it is writing to the plugin code itself. It was either many files and 1 code line per plugin, or 1 file and 2 code lines per plugin. I wanted 1 file and 1 line per plugin :D So begins tutorial proper... Advanced Plugin Optimization System You should know what code is in your plugins, how they work, how to find hooks, etc - I'm not getting into that. I'm also assuming you know how to code PHP in general, and know what functions/OOP I'm talking about, and can look up any you don't. First create the file that will house the plugin code and put it somewhere. I will use the file myhack_plugins.php in the plugins subfolder in the forum root. Create all of your plugins in the ACP plugin manager that you would normally use, and put the exact same single line in each them: PHP Code:
Create a functions file that has this in it: PHP Code:
PHP Code:
Figure out which hook executes very first in your hack. The very first in vBulletin at all is init_startup, and you might want to add a plugin at that hook just to make sure the system works. Remember what your first hook is. Now, in the plugins file, it works like this: PHP Code:
Benefits
You can see this optimization system in use in my vBCredits 1.4rc2 hack here or here. The older version of this (not quite as good, but what I was doing before perfecting this system) is in use in my vBTracker LITE hack here. |
Excellent article!
Easy enough to understand (even for me, only starting out!), and a great idea for creators of some of the larger hacks. Just let me get this straight though. You should end up having: 1) ./includes/functions_myhack.php that collates the plugins called by your hack, last one first. 2.) ./plugins/myhack_plugins.php that calls ./includes/functions_myhack.php and switches between the plugin locations for the correct code to insert. 3. All your hooks that you use in myhack_plugins.php switch set in the plugin manager, but with the code to include myhacks_plugin.php And that's it?! Would there be a number of plugins you recommend having in a hack before using this method? |
:D very glad you understood it as a beginner - I really didn't want to explain every little detail as the big picture is a little abstract itself.
You have it down pretty well! Again if you want to see real application of this, look at my demo links of hacks I've used it with. This actually wouldn't be necessary if vBulletin reported the hook that is currently executing, but it doesn't, and the hook class needs to be edited to do so. My other goal I guess, was to provide a solution that end-users wouldnt have to do anything out of the ordinary to install, and certainly not do any file edits. :) As for the minimum number of plugins "needed" is kind of blurry. One of the things this allows you to do is work on your plugins all at once in your favorite code editor. You could have one huge plugin in total, but would still be really useful to not copy/paste between the vB Plugin system. Of course, any extras like that would simply compound the problem. Then there is the fact that vB caches ALL active plugins in the datastore which are loaded on every single page as text stored in memory. You help your end-users with database memory, RAM, and speed by using this system, that much more so when they have dozens of hacks installed at once (One site in particular had over 250 hacks installed, and getting anything to load was a ten minute affair - imagine if all of his 1,000 plugins weren't sitting in memory in all their glory?) About the only time you shouldn't bother putting plugin code in this system is if the line of code is one line long anyway and you don't intend to change it very often. About the only thing I can think of like that is the templategroup definition plugin :-p Finally, if at the end of development you see some plugins ended up as one line, then move those ones back into the vb plugin space :) Thanks for reading! |
Quote:
Quote:
(But mostly that was gibberish to me! Talk about hooks and I'm pretty vague except for the notion they exist!) Now all that's needed (for me anyway) is to put hooks in the files that have few or none, and use this. Quote:
I think I'll be using this to convert two of the hacks I have with the most plugins (Andreas' TMS & Interactive Profiles) Quote:
Quote:
I think I'll be using this to convert two of the hacks I have with the most plugins (Andreas' TMS & Interactive Profiles) - should be more educational to try it with someone elses before my own :D |
Aha, you are right: I would like to rescind the statement about inactive plugins being cached. They are not. Doesn't change much of anything else though :-p
Let me know how conversion of those hacks goes :D I havent tried it on someone else's hack, but you shouldnt have any issues at all. Just make sure the namespaces are unique and everything will work out :) |
A few weeks ago it was brought to my attention that the system gets messed up if a plugin that executes before your plugins contains other hooks...
So, this new version which I updated the first post with, takes care of that issue. I have also uploaded some prototype files to get you started with, so dont be afraid to use this :D The couple of people who have tried it ended up really liking how well it works. As always, if you use this in your hack with success I would love to see it, or if you have questions dont hesitate to ask here or through any method on my profile. |
I highly recommend this system it is a developers dream :) Helped me out so much and made things so much easier. Especially when you have thousand line code snippets hooked this makes it so much easier to edit and test things and so on. If you don't use this your wasting hours of your time.
|
As a newbie to any type of coding I'm trying to wrap my head around this... I think I know whats going on but am afraid to attempt any of it.
Is this something I should wait to attempt until I have made the transition to the stable release of 3.8? Thanks' Gary |
This will work with vb3.6/7/8. It might also work with vb3.5, but I havent tried it so cant say with certainty.
In a nutshell, what this system does is report to your plugins what hook they belong to. While it seems unneccesary, it allows you to move all of your plugins into a single file with just one repeated include line in your plugins. Doing this has all of the benefits listed in the top post. Note, you may run into problems when trying to use hacks using the two different plugin systems (the one i posted previously, and this current one) if you do, send me a PM and I will explain the solution. I dont want to further confuse people with it unless it applies to them :-/ |
Thank you :) really this helped me out! I will transfer to plugin file system because I have many plugins, of course will test it on a vBulletin test forum with test database :)
|
All times are GMT. The time now is 02:47 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|