MyBB Hacks

Full Version: Preparser Cache
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7
This is a fairly simple pre-parser modification which should speed up one of MyBB's slowest functions.
Basically, MyBB's MyCode parser is rather slow; this plugin speeds this component up by caching the result so that the parser does not have to be run on every single page request (this is assuming that SHA1 hashing + a single query with some string manipulation is faster than running the parser 20+ times).

This plugin is compatible with all supported DB engines (SQLite in MyBB 1.6.0 is bugged, so cannot be tested).

Compatibility with other plugins
Due to the fact that this modification changes the environment under which the parser is run, I cannot guarantee that this will work with all MyCode/HTML or parser related plugins, especially those that may display posts differently to different users (on the other hand, this actually may have the potential to remove some of the issues in some poorly coded modifications).  Custom MyCodes should still work, and there is a workaround for the vB Quote plugin.
This will not work with the HTML in Posts plugin.

About design
The design of this is much simpler than my mod for MyBB 1.2, and as such, is nowhere near as aggressive, however, it's something I (originally!) banged up together in about an hour, and gets most of the benefits anyway.  It differs from both my 1.2 mod, and Ryan Gordon's 1.4 mod in that it operates at a parser level instead of at the showthread/postbit level.

The plugin only does posts and signatures on showthread.php, but it can be quite easily modified for other places, as it operates on a parser level.  Again, this was something I wrote fairly quickly, and could use a number of improvements in some areas.
The cache is periodically cleaned via a cleanup task.

Note that this plugin also provides a way to manually clear the cache, under the Recount & Rebuild section of the AdminCP, should you ever have the need to do so.

Known Issues
  • Attachments embedded with the [attachment=id] code may not have their download count updated
  • A very minor one - it's possible to cause this plugin to display removed attachments embedded in the post (will be a dead link though).  Standard MyBB behavior will simply ignore the [attachment=id] code.  This will do the same if the post is updated in any way.
  • For MyBB 1.8, quote times will be forced to use absolute time (instead of relative).  For earlier versions, there is no change to the timestamp displayed, however the "Today" and "Yesterday" text will never get updated (until a cache clear), so this can be inaccurate if this occurs

Simple Benchmark
Just a simple benchmark I performed to get an idea of the speed gains of this plugin.  I'm benchmarking this page, with and without the plugin.  I guess the page is somewhat a good candidate for this plugin, although I didn't exactly cherry pick it on purpose.

Times were recorded by just using the time metric at the bottom of the page.  Note that the plugin does a number of things after the timer has completed, so I've also made a comparison after modifying MyBB's timer to more accurately measure the time (if you don't perform this modification, the preparser mod should pretty much always make your showthread pages seem to run faster).
Pages were loaded 3 times.

Standard behaviour: 0.2359838s, 0.2380810s, 0.2462718s
Standard behaviour, after editing timer: 0.2320759s, 0.2335730s, 0.2380040s
With preparser (with timer edit): 0.1327140s, 0.1319780s, 0.1258268s
With preparser (without timer edit (inaccurate)): 0.1291881s, 0.1186280s, 0.1211529s

Initial load with preparser, timer edit: 0.2454121s (this is the page load which caches everything - it'll be slower than normal page loads, but subsequent requests will be much faster)

1.0 benchmarks:
Standard behaviour: 0.2242870s, 0.2201211s, 0.2377510s
Standard behaviour, after editing timer: 0.2399340s, 0.2398720s, 0.2158720s
With preparser (with timer edit): 0.1303909s, 0.1500199s, 0.1303349s
With preparser (without timer edit (inaccurate)): 0.1157429s, 0.1143448s, 0.1083250s
nice plugin.
Not quite sure how to test it, Yumi. Should we clear our cache each time we reload the pages?

I did this benchmark without clearing my cache each time the pages reload. I clear my cache once before the first test without plugin, and once before the first test after installing the plugin. I didn't do the timer modification.

Without installing this plugin:
0.1336341, 0.1638100

0.0933359, 0.1411159

Wow, my showthread page load faster, Yumi!
No you probably shouldn't be clearing the cache each time you test it, since it'll always be slower than default (since it needs to build the cache if it has been cleared).  Note that without a timer modification, you won't see it being slower though.
I tested it without any modification, Yumi. Plugin installed is only Cool Codes plugin (MyBB 1.6). So, my result is inaccurate, Yumi?
Yes, it'll be a bit inaccurate.

If you want to do the timer modification, edit inc/functions.php, find the line:

PHP Code:
$contents = $plugins->run_hooks("pre_output_page", $contents);

Cut it and move it after this line:

PHP Code:
$contents = parse_page($contents);

This will force this plugin to run before the timer stops.

Wow! + no core file hacks this time, thanks ZB!  Smile

I cannot guarantee that this will work with all MyCode plugins...

In general,
won't work = page loads the normal slower way
This plugin + poorly coded plugin = Fatal error...  ?
Won't work refers to the other plugin possibly being broken in some way.
Great to see Preparser Cache is back, thanks.
RateU pointed out that this plugin doesn't handle [attachment=] style tags properly.

Unfortunately, I don't see a good way of resolving this, considering how this plugin was designed, so I'll probably need to re-create it in a completely different way.
Sorry about that.
Pages: 1 2 3 4 5 6 7
Reference URL's