Re: thoughts on memory usage...

From: David Luyer <luyer@dont-contact.us>
Date: Tue, 19 Aug 1997 14:11:09 +0800 (WST)

  This message is in MIME format. The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--1602371712-1845522394-871971069=:8099
Content-Type: TEXT/PLAIN; charset=US-ASCII

Re: Michael's suggestoin of a URL compression scheme for in-memory URLs.
I've implemented a simple URL compression scheme as a filter to see how
good this would be, and it seems feasable assuming that the URL can be
encoded/decoded at the right times without causing too many problems.

I'm getting 33% compression (65484675 bytes, including trailing \n's on
disk, into 44138496 bytes) using 10 or so URL prefixes, URL suffixes and
host suffixes. The substrings were just things which I thought up as
'probably fairly common', I'm sure a much better set could be found. I
haven't written the decompress routine to verify this is reversable on all
URLs, but I believe I've considered all quoting, etc, needed.

[note - the trailing \n's on disk are equivalent to trailing \0's in
memory]

I've attached the source code I'm using; I'm not sure how I'll determine
the "optimal" string set or what compression that'll give, hopefully over
33% but probably less than 50%. Then there's the issue of inserting calls
to compress/decompress URLs at interactions with the outside world (Qstn:
should "log" be 'compressed'?).

The "encode" routine probably uses too many malloc()s/free()s. A static
buffer might be the answer (since the code doesn't have to be threadsafe,
and we have a max url length). It could also be sped up by caching the
results of pointer dereferences and strlen calls; I'll do this later. The
"decode" routine is half written, completely broken, and will segfault if
you try to use it.

The source code is currently for Linux, and uses malloc/strdup instead of
xmalloc/xstrdup, but should work on any OS with a strdup() in its libc
(ie, anything with the slightest BSD influence).

/* pfx/sfx strings MUST be sorted in ascending order of string length
 * since the "first longest" match is used.
 *
 * encoding:
 * encode URL PFX
 * * examples assume PFX string A is "http://www."
 * * {full-pfx-match} -> pfx-letter eg http://www. -> A
 * * {partial-pfx-match} -> pfx-letter, len eg http://www- -> A10
 * * quoting - a following numeric, quote with \
 * eg http://www8 -> A\8
 * - quote a following \ eg,
 * http://www.ibm.com/\thingy ->
 * Z\\thingy
 * if PFX string Z was http://www.ibm.com/
 * encode HOST SFX
 * * work back from 3rd / in original URL
 * * full/partial matches, use pfx_char[len] for partials
 * ie. string A = ".x.com"; .y.com/ -> AD/
 * * no quoting of following char since it must be a /
 * * no quoting of preceeding char since it must not be a capital
 * or special in a hostname
 * * do not compress/encode already encoded data
 * encode URL SFX
 * * work back from terminating NULL
 * * do not compress/encode already encoded data
 * * if there is no SFX string, add a # to quote preceeding char
 * if it is a possible SFX char or digit
 * * full/partial matches, as above
 * don't let URL SFX enclose 3rd /
 * if URL PFX has no length element and runs in to HOST SFX, seperate
with !
 * if(strlen(out) > strlen(in) + 1)
 * out = in ++ "#";
 */

/* example output of test prog:
 * http://www20.ibm.com/index.html [31] --> E10\20.A/G [10]
 * (when input: http://www20.ibm.com/index.html)
 */

Opinions, comments, suggestions, anyone?

David.

--1602371712-1845522394-871971069=:8099
Content-Type: TEXT/plain; name="url-comp.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.3.96.970819141109.8099E@typhaon.ucs.uwa.edu.au>
Content-Description: url-comp.c

I2RlZmluZSBfQlNEX1NPVVJDRSAxDQojaW5jbHVkZSA8Y3R5cGUuaD4NCiNp
bmNsdWRlIDxzdGRpby5oPg0KI2luY2x1ZGUgPG1hbGxvYy5oPg0KI2luY2x1
ZGUgPHN0cmluZ3MuaD4NCg0KLyogcGZ4L3NmeCBzdHJpbmdzIE1VU1QgYmUg
c29ydGVkIGluIGFzY2VuZGluZyBvcmRlciBvZiBzdHJpbmcgbGVuZ3RoDQog
KiBzaW5jZSB0aGUgImZpcnN0IGxvbmdlc3QiIG1hdGNoIGlzIHVzZWQuDQog
Kg0KICogZW5jb2Rpbmc6DQogKiAgIGVuY29kZSBVUkwgUEZYDQogKiAgICAg
ICAgKiBleGFtcGxlcyBhc3N1bWUgUEZYIHN0cmluZyBBIGlzICJodHRwOi8v
d3d3LiINCiAqICAgICAgICAqIHtmdWxsLXBmeC1tYXRjaH0gLT4gcGZ4LWxl
dHRlciAgICAgICAgICBlZyBodHRwOi8vd3d3LiAtPiBBDQogKiAgICAgICAg
KiB7cGFydGlhbC1wZngtbWF0Y2h9IC0+IHBmeC1sZXR0ZXIsIGxlbiAgZWcg
aHR0cDovL3d3dy0gLT4gQTEwDQogKiAgICAgICAgKiBxdW90aW5nIC0gYSBm
b2xsb3dpbmcgbnVtZXJpYywgcXVvdGUgd2l0aCBcDQogKiAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVnIGh0dHA6
Ly93d3c4IC0+IEFcOA0KICogICAgICAgICAgICAgICAgICAtIHF1b3RlIGEg
Zm9sbG93aW5nIFwgZWcsDQogKiAgICAgICAgICAgICAgICAgICAgICBodHRw
Oi8vd3d3LmlibS5jb20vXHRoaW5neSAtPg0KICogICAgICAgICAgICAgICAg
ICAgICAgICAgICBaXFx0aGluZ3kNCiAqICAgICAgICAgICAgICAgICAgaWYg
UEZYIHN0cmluZyBaIHdhcyBodHRwOi8vd3d3LmlibS5jb20vDQogKiAgIGVu
Y29kZSBIT1NUIFNGWA0KICogICAgICAgICogd29yayBiYWNrIGZyb20gM3Jk
IC8gaW4gb3JpZ2luYWwgVVJMDQogKiAgICAgICAgKiBmdWxsL3BhcnRpYWwg
bWF0Y2hlcywgdXNlIHBmeF9jaGFyW2xlbl0gZm9yIHBhcnRpYWxzDQogKiAg
ICAgICAgICAgICAgICAgICAgICBpZS4gc3RyaW5nIEEgPSAiLnguY29tIjsg
IC55LmNvbS8gLT4gIEFELw0KICogICAgICAgICogbm8gcXVvdGluZyBvZiBm
b2xsb3dpbmcgY2hhciBzaW5jZSBpdCBtdXN0IGJlIGEgLw0KICogICAgICAg
ICogbm8gcXVvdGluZyBvZiBwcmVjZWVkaW5nIGNoYXIgc2luY2UgaXQgbXVz
dCBub3QgYmUgYSBjYXBpdGFsDQogKiAgICAgICAgICBvciBzcGVjaWFsIGlu
IGEgaG9zdG5hbWUNCiAqICAgICAgICAqIGRvIG5vdCBjb21wcmVzcy9lbmNv
ZGUgYWxyZWFkeS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9PSAnLycgJiYgc2xhc2ggPT0gMikgew0KICAgIHB0ci0tOw0K
ICAgIGlmKChwMiA9IHN0cmNocihwZnhfY2hhciwgKnB0cikpKSB7DQogICAg
ICBzZWcybGVuID0gczJsID0gMDsNCiAgICAgIHMybDIgPSAxOw0KICAgICAg
d2hpbGUoKHAyMiA9IHN0cmNocihwZnhfY2hhciwgKi0tcHRyKSkpIHsNCiAg
ICAgICAgc2VnMmxlbiA9IHNlZzJsZW4gKyBzMmwyICogKHAyMiAtIHBmeF9j
aGFyKTsNCiAgICAgICAgczJsMiAqPSAxMDsNCiAgICAgICAgczJsKys7DQog
ICAgICB9DQogICAgfQ0KICB9DQogIHJldHVybiBsZW47DQp9DQoNCmNoYXIg
Km1haW4oKSB7DQpjaGFyIGJ1Zls0MDk2XSwgKnN0cjsNCg0KICB1cmxfY29t
cHJlc3NfaW5pdCgpOw0KICB3aGlsZShnZXRzKGJ1ZikpIHsNCiAgICBwcmlu
dGYoIiVzIFslZF0gLS0+ICVzICIsIGJ1Ziwgc3RybGVuKGJ1ZiksIHN0ciA9
IHVybF9lbmNvZGUoYnVmKSk7DQogICAgcHJpbnRmKCIgWyVkXVxuIiwgc3Ry
bGVuKHN0cikpOw0KICAgIGZyZWUoc3RyKTsNCiAgfQ0KICByZXR1cm4gMDsN
Cn0NCg==
--1602371712-1845522394-871971069=:8099--
Received on Tue Jul 29 2003 - 13:15:42 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:22 MST