Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Language Optimizations (beta)
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #1
Language Optimizations (beta)
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 Tongue

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)


Attached File(s)
.zip  langopt.zip (Size: 3.68 KB / Downloads: 740)

My Blog
(This post was last modified: 01-26-2008 11:53 AM by ZiNgA BuRgA.)
01-26-2008 11:50 AM
Find all posts by this user

« Next Oldest | Next Newest »

Messages In This Thread
Language Optimizations (beta) - ZiNgA BuRgA - 01-26-2008 11:50 AM
RE: Language Optimizations (beta) - dared - 03-19-2008, 12:55 AM
RE: Language Optimizations (beta) - dvb - 03-19-2008, 10:43 AM
RE: Language Optimizations (beta) - dvb - 03-19-2008, 09:52 PM
RE: Language Optimizations (beta) - dared - 03-27-2008, 03:29 AM
RE: Language Optimizations (beta) - dared - 03-31-2008, 04:39 AM
RE: Language Optimizations (beta) - Guest - 05-06-2008, 07:50 AM
RE: Language Optimizations (beta) - Guest - 05-29-2008, 03:19 AM
RE: Language Optimizations (beta) - Guest - 05-30-2008, 03:02 AM
RE: Language Optimizations (beta) - Guest - 05-31-2008, 02:40 AM
RE: Language Optimizations (beta) - Guest - 06-05-2008, 02:46 AM

 Standard Tools
Forum Jump: