Extension:PhpTags/Performance

The PhpTags extension is designed to obtain the best possible MediaWiki extensions performance without using any additional components (only pure PHP code).

This is achieved by using the concept of Magic expressions instead of Magic words. Although PhpTags himself uses the technology Magic words, but it allows to reduces to a minimum overhead of usage other extensions.

Time that takes PhpTags consists of:
 * analysis of expression
 * execution of instructions
 * data transfer between extensions
 * time spent by the extensions

PhpTags works so rapidly that when used under the concept of the magic expressions the run time is negligible or it is not possible to measure.
 * The main part of the code should be in the extensions, and in the PhpTags placed instructions which features of these extensions, and in what order to use.

Of course, you can use this application as you wish, and in order to find out the effectiveness (as possible) this solution, I ran some tests using MediaWiki 1.23.1 and PhpTags 3.0.0.
 * All of these tests can give only a general overview of performance since they use completely different approaches and technologies.

Compared to Magic Words
For comparison I took two nested loops of 20 loops each, a total of 420 loops.

MediaWiki with PhpTags faster Magic words in more 86 times. ( 5.950 / 0.069 = 86.232 ) The next time bytecode will be taken from the cache, and PhpTags will be faster more 95 times. ( 5.950 / (0.069-0.007) = 95.968 )

Compared to pure PHP
For a more accurate measurement I increased the number of cycles up to 100100


 * The comments indicate the number of instructions that PhpTags has executed.

Test Results: PhpTags: 11.462 secs PHP: 0.029 secs PhpTags/PHP: 394.573

As it can be seen PhpTags in this test is slower pure PHP almost in 400 times. But PhpTags has executed 1 302 005 instructions per 11.462 seconds and one instruction took the less 0.00001 second.

I'm sure PHP uses some hack for cycles, so I did another test where few cycles and a lot of code.

Test Results: PhpTags time usage: 0.332 sec Compiler: 0.272 sec Runtime: 0.060 sec Pure PHP: 0.00235 sec PhpTags/PHP without compiler cache: 0.332 / 0.00235 = 141 PhpTags/PHP with compiler cache: 0.060 / 0.00235 = 25 Since the runtime also includes the initialization of the PhpTags Functions classes I did another test where this code is duplicated ten times. Initialization occurs only once therefore I divide the runtime by 10 and get more accurate results where the initialization is less significant role.

Runtime: 0.484 / 10 = 0.0484 sec Pure PHP: 0.00235 sec PhpTags/PHP: 0.0484 / 0.00235 = 20.6

Well, something like that. You should try not to use loops with PhpTags if you want to get the best performance.

Compared to Scribunto (Lua)
It would seem what can be compared here? It is well known that Lua is due to the simple implementation works several times faster than PHP. In the test cycles given above PHP took 0.029 second and Lua takes only 0.008 second. It turns out that this is the fastest solution, and this is the best that can be used to increase performance Mediawiki.

In practice, this is not quite true.

Even if you move away from the concept of Magic expressions and will use PhpTags for writing scripts in the same way as is done in Scribunto, MediaWiki with PhpTags is still runs faster in two or more times than Scribunto. Perhaps this is due to the fact that the Scribunto requires some resources to initialize Lua, while PhpTags has no such overhead.

For testing, I used a ready-made module drawing markers on the map. I tried to rewrite it in the same manner but using PhpTags (Template:Location_map).

So here's what I got in the end: