01-26-2008, 11:50 AM
You may be surprised how much you can optimize MyBB through it's language system...
How the MyBB language system works
There are a number of .lang.php files under /inc/languages/[your language]/ folder.
The language variables are stored as an $l array. However, MyBB internally stores langvars in the $lang object. So, every time a language file is loaded, there's a small delay in copying the contents of the $l array to the $lang object.
However, the main overhead is the preg_replace() function which is used to parse each language var. This converts {1}, {2} etc to something which is usable by sprintf().
How this plugin works
This works by causing language vars to be directly assigned to the object, rather than performing a second copy. Also, the langvars are preparsed, so that preg_replace() doesn't have to be run over each variable each time a language file is loaded. Additionally, this uses single quotes, which is faster for PHP to parse than double quotes
Side effects?
Basically none. This plugin will fix the AdminCP language editor, so everything will seem normal. The only difference is perhaps if you edit the .lang.php files directly. You'll notice that there's a slightly different format, and that {1}, {2} etc are preparsed to %1$s, %2$s etc. Shouldn't be hard to figure out anyway.
The results?
On a test board, I got around a 10-30% reduction in page generation times. Not that much, but then, there's little to lose here, so why not?
Installation
Upload to your /inc/plugins folder. Make sure the appropriate language files are writable, for example, make sure you CHMOD /inc/languages/english and all files inside the folder to 0666.
After that, activate the plugin (note, on activation/deactivation, the plugin will rewrite all your .lang.php files).
Note: since this doesn't change MyBB core behaviour, plugins still using the older $l notation will work perfectly fine. If you want to optimize those files however, simply edit them in the AdminCP language editor, and the file will be rewritten with the optimizations in place. (alternatively, reactivate the plugin)
How the MyBB language system works
There are a number of .lang.php files under /inc/languages/[your language]/ folder.
The language variables are stored as an $l array. However, MyBB internally stores langvars in the $lang object. So, every time a language file is loaded, there's a small delay in copying the contents of the $l array to the $lang object.
However, the main overhead is the preg_replace() function which is used to parse each language var. This converts {1}, {2} etc to something which is usable by sprintf().
How this plugin works
This works by causing language vars to be directly assigned to the object, rather than performing a second copy. Also, the langvars are preparsed, so that preg_replace() doesn't have to be run over each variable each time a language file is loaded. Additionally, this uses single quotes, which is faster for PHP to parse than double quotes
Side effects?
Basically none. This plugin will fix the AdminCP language editor, so everything will seem normal. The only difference is perhaps if you edit the .lang.php files directly. You'll notice that there's a slightly different format, and that {1}, {2} etc are preparsed to %1$s, %2$s etc. Shouldn't be hard to figure out anyway.
The results?
On a test board, I got around a 10-30% reduction in page generation times. Not that much, but then, there's little to lose here, so why not?
Installation
Upload to your /inc/plugins folder. Make sure the appropriate language files are writable, for example, make sure you CHMOD /inc/languages/english and all files inside the folder to 0666.
After that, activate the plugin (note, on activation/deactivation, the plugin will rewrite all your .lang.php files).
Note: since this doesn't change MyBB core behaviour, plugins still using the older $l notation will work perfectly fine. If you want to optimize those files however, simply edit them in the AdminCP language editor, and the file will be rewritten with the optimizations in place. (alternatively, reactivate the plugin)