|Well, it's incorrect in two major ways:|
- The spec says to compress everything after the negotiation. Not to compress, per message. It says it "may be desirable" to terminate compression at some point, however I take that to mean in situations like a hotboot, or if the client requests compression to stop for some reason.
- It defeats most of the point of compression in the first place. Compression works by looking for redundancies in text (which is why you can't successfully compress random data). By stopping and starting the compression, per message, you throw away its "dictionary" of words that are being repeated. See below for more details.
The MCCP protocol uses zLib, which is available in MUSHclient's Lua interface, so it is easy to demonstrate the difference. This script I wrote in the Immediate scripting window:
COUNT = 10
orig = [[
You are standing within the expanse of the famous Darkhaven Square. A
stone statue of occupies the square's center, surrounded by gardens of
shrubbery which enhance the air of serenity and peace here in the center
of the city. The main road lead away in the cardinal directions, while
to the northeast and northwest are forested paths. The spires of a
cathedral can be seen rising to the northwest.
Exits: north east south west up northeast northwest.
print ("size of orig =", #orig)
comp = utils.compress (orig)
print ("size of comp =", #comp)
orign = string.rep (orig, COUNT)
print ("size of orign =", #orign)
compn = utils.compress (orign)
print ("size of compn =", #compn)
print ("size of comp X", COUNT, "=", #comp * COUNT)
size of orig = 472
size of comp = 271
size of orign = 4720
size of compn = 311
size of comp X 10 = 2710
Let's assume someone is standing in Darkhaven Square, typing "look" 10 times. The figures show the difference.
The first figure (472) is how much is sent uncompressed, each time. And after 10 times, we have sent 4720 bytes.
The first time, the compressed figure is shorter, certainly - 271 bytes. However after 10 times, we get a big difference:
- Keeping a compressed stream: 311 bytes - only slightly more than typing "look" once.
- Stopping and restarting compression: 2710 bytes (271 times 10). Plus we need to add in the IAC SB COMPRESS SE bytes to *each* packet, so it is really 275 * 10, namely 2750 bytes.
So, by doing it the recommended way, you have only sent 11% of the amount of text, after the player only typing "look" 10 times.
I'm just trying to point out that turning compression on and off isn't just another way of achieving the same result, it is much much worse.
- Nick Gammon
| top |