Featured

Thursday, December 16, 2010

MMC : Secondary Promotion : Experimental results

I spent quite some time working on Secondary promotion lately. The algorithm was particularly complex, and ensuring that all corner cases were correctly addressed required many debug iterations.

In the end, i finally completed a new version of SecFull, an aggressive implementation which tries to promote all characters it meets during its travel across the different levels. The changes required the capability to "move back" by one level, since in some cases, chains were broken and needed repair.

A much simpler version was produced in the process, called Sec1. It just tries to promote the last seen character, and only when a valid gateway is confirmed. This ensures that the changes are minimal and well located, keeping all the rest of the code unmodified.
Complexity difference between Sec1 and SecFull is quite large, and therefore it is not so clear which one will bring better benefit.

Anyway, it is now possible to compare. All search algorithms generate exactly the same references, resulting in the same output. Therefore, all changes affect only the speed of searches.

As usual, let's just start by a simple counter of comparisons :

Nb of comparisons - Window Search 64K :
FileNoSecSec1SecFull
Calgary4.87M4.31M3.70M
Firefox35.2M31.2M25.7M
Enwik8166.M139.M121.M
Window Search 512K :
FileNoSecSec1SecFull
Calgary9.31M7.94M6.32M
Firefox78.2M67.3M52.9M
Enwik8370.M285.M238.M
Window Search 4M :
FileNoSecSec1SecFull
Calgary12.0M10.2M7.95M
Firefox161.M141.M114.M
Enwik8619.M472.M357.M
The trend is pretty clear : the more aggressively we promote, the less comparisons are necessary to complete a full search. And the difference is more and more pronounced as the size of search buffer increases.
That's for comparisons. Now, what about speed ?
Surely, the less number of comparisons, the better the speed ?
Well, yes, approximately; but we also have to take in consideration code complexity. If each search is "more costly", then the total may end up being slower.
As can be guessed, Sec 1 is more complex than NoSec, and SecFull is the most complex of all. So, does it pay back ? Here are some results :

Speed - Window Search 64K :
FileNoSecSec1SecFull
Calgary32.8 MB/s31.5 MB/s32.0 MB/s
Firefox40.5 MB/s38.9 MB/s40.0 MB/s
Enwik830.8 MB/s29.9 MB/s30.1 MB/s
Window Search 512K :
FileNoSecSec1SecFull
Calgary16.6 MB/s16.9 MB/s17.9 MB/s
Firefox19.4 MB/s18.6 MB/s19.9 MB/s
Enwik813.0 MB/s13.2 MB/s14.7 MB/s
>Window Search 4M :
FileNoSecSec1SecFull
Calgary6.5 MB/s6.8 MB/s8.1 MB/s
Firefox2.3 MB/s2.4 MB/s2.7 MB/s
Enwik81.9 MB/s2.4 MB/s3.0 MB/s

Time for some serious thinking.
Even with less comparisons, the new algorithms are not guaranteed to be faster. This is especially true at 64K, where all Secondary algorithm fail to produce any gain, even though the number of comparisons is well reduced.
We need larger search buffer to make Secondary promotions worthwhile. And this is reached as soon as 512K, and then growing with search size.

Actually, SecFull seems to win over Sec1 in each and every circumstance. So it can be preferred.

But to be fair, results are a bit disappointing. The very large difference in comparison loops would make us believe that the benefit could be larger. But in the end, it is still relatively mild.
No ground-breaking progress this time...

No comments:

Post a Comment