tungwaiyip.info

home

about me

links

my software

Media

Yucatán Photos

St Lucia Photos

Photo Album

Videos

Blog

< April 2010 >
SuMoTuWeThFrSa
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
252627282930 

past articles »

Click for San Francisco, California Forecast

San Francisco, USA

 

The Power of Gzip

I know Information Theory says that good data compression will shrink a message down to its entropy. So for application developers, it is not productive to design our own spacing saving encoding scheme if we plan to apply data compression at the end anyway. Because the original message and the encoded message contain the same amount of information, the compressed data will end up with approximately the same size.

I don't realize how true it is until I have actually tried it. I am working with a CSV file with mostly integer data. I am very keen on reducing its size to save storage and network bandwidth. So I tried several schemes. They all failed to make significant saving once gzipped.

The first attempt is on the minus sign. I notice there are a lot of negative numbers. The '-' sign occupies one bytes, but it only carries one bit of information. What if I apply a simple encoding, e.g. using 'A' to stand for '-1', and 'B' stand for '-2' and so on? Trimming the negative sign with this encoding cut down the storage by 6%.

  e.g.
    "108,-2,-10"  ->  "108,B,A0"

What about the result after gzipping? Gzip shrinks the original data down to 34%. For the encoded message, it is 36%. The difference between the two? A negligible 0.1%.

Next attempt, it seems wasteful to store an integer as string using only 10 decimal digits per character. What if we use the hexadecimal representation? The conversion is trivial and it should cut down the string length a bit. If this is fruitful we may even try to use a higher base. Using the hexadecimal scheme, we reduce the storage by 7%. But once gzipped, the saving again evaporates.

A far more lucrative approach is to abandon text format altogether and use binary encoding for the numbers. Since the order of the number differ a lot, I use a kind of variable length integer encoding to make it economical for both small and large numbers. The binary encoding deliver the most significant saving by cutting down the storage by 44%. The text data and the binary encoded data seem very different initially, not to mention its size is nearly half of the original. But once gzipped, the binary data is only 4% smaller. Despite the big difference in representation, the compressed data is still proportional to the entropy. The 4% gain is hardly enough to justify using binary format over text.

The lesson learned? Don't be too concern about the efficiency of storing number in text format like CSV. Data compression will take out the inefficiency in one easy step.

Finally I like to mention some encoding that works for me. The data is initially available in XML format. Dropping the XML baggage and store it in CSV format saves a lot. Secondly, storing only the delta of the numbers works very well in my application. Furthermore, slightly reducing the precision of the numbers, a sort of lossy compression, also deliver a meaningful saving. More importantly, the saving still present after compression.

2010.04.19 [] - comments

 

 

blog comments powered by Disqus

past articles »

 

Kontagent

Kontagent is hiring software engineers

BBC News

 

Gulf states fuel Syria isolation (07 Feb 2012)

 

New Maldives leader pledges order (07 Feb 2012)

 

Iranian president summoned by MPs (07 Feb 2012)

 

LA abuse school removes all staff (07 Feb 2012)

 

Uganda MP revives anti-gay bill (07 Feb 2012)

 

California court backs gay unions (07 Feb 2012)

 

Monaco royals in privacy defeat (07 Feb 2012)

 

Royals celebrate Dickens' legacy (07 Feb 2012)

 

Euro 'could survive Greece exit' (07 Feb 2012)

 

Obama to give back campaign funds (07 Feb 2012)

more »

 

Slashdot News for nerds, stuff that matters

 

Saylor Foundation Awards Prizes To Free College Textbooks (2012-02-07T22:15:00+00:00)

 

Fracture Putty Can Heal a Broken Bone In Days (2012-02-07T21:32:00+00:00)

 

Apple Could Lose .6 Billion In iPad Lawsuit (2012-02-07T20:51:00+00:00)

 

Google Releases Chrome For Android Beta (2012-02-07T20:09:00+00:00)

 

The 20th IOCCC Winners Announced (2012-02-07T19:46:00+00:00)

 

Programming Error Doomed Russian Mars Probe (2012-02-07T19:25:00+00:00)

 

Honeywell Vs Nest: When the Establishment Sues Silicon Valley (2012-02-07T18:42:00+00:00)

 

DARPA Investing In Electric Brain Stimulation To Train Snipers Quickly (2012-02-07T18:19:00+00:00)

more »

 

TechPsychic Tech Rumors and Invented News

 

TechPsychic: AT&T: more money, says it's disruptive in funding from. (08 May 2010)

 

TechPsychic: I know that Apple is close to Apple Dominates, Hires ex-Googler - Yes, Android phones. (08 May 2010)

 

TechPsychic: AT&T says: Facebook Connect. (08 May 2010)

 

TechPsychic: Google's Nexus One of Google Chrome Release Adds Support subscriptions accounted for Amazon: Apple. (08 May 2010)

 

TechPsychic: Another stat: Twitter's Design of this is giving rise of BlackBerry Foursquare Map App store end. (07 May 2010)

 

TechPsychic: Like educational sales Up around Apple iPad makes money Plan costs half an Apple. (07 May 2010)

 

TechPsychic: Instead added extensions, social Networks than double, everyone jumps in Silicon Valley? (07 May 2010)

 

TechPsychic: So why iTunes App lets Social Networks Verizon Wireless Internet. (07 May 2010)

more »

 

SF Gate

 

A U.S. appeals court rules Prop. 8 unconstitutional (2012-02-07T22:52:57PST)

 

Excerpts from today's Prop. 8 ruling (2012-02-07T22:52:57PST)

 

Editorial: Wise ruling against Prop. 8 (2012-02-07T22:52:57PST)

 

Timeline of gay marriage in California (2012-02-07T22:52:57PST)

 

Prop. 8 judge strikes down same-sex marriage ban (2012-02-07T22:52:57PST)

 

Komen exec quits after Planned Parenthood flap (2012-02-07T22:52:57PST)

 

Correction: GOP Campaign story (2012-02-07T22:52:57PST)

 

Job openings jump to near a 3-year high (2012-02-07T22:52:57PST)

 

Job openings jump to near a 3-year high (2012-02-07T22:42:27PST)

 

Stocks turn higher on strong job openings (2012-02-07T22:42:27PST)

 

Oracle rejects SAP award, demands new trial (2012-02-07T22:42:27PST)

 

Catholic hospitals split on giving contraceptives (2012-02-07T22:42:27PST)

 

Time for taxes means time for questions (2012-02-07T22:42:27PST)

 

BofA Investor Suit Over Merrill Deal Granted Class Status (2012-02-07T22:42:27PST)

more »

 

Asia Times Online

 

Pakistan snubs US over Osama informer (7 Feb 2012)

 

Obama switches play on war with Iran (7 Feb 2012)

 

Gulf crisis ripples across the globe (7 Feb 2012)

 

US weighs options as Syrian violence rises (7 Feb 2012)

 

Kidnaps highlight urgent task for China (7 Feb 2012)

 

Beijing finds vulnerable ally in Berlin (7 Feb 2012)

 

Kicking down the world's door (7 Feb 2012)

 

Chinese give boost to illegal ivory trade (7 Feb 2012)

 

Confidence in Nabucco fades (7 Feb 2012)

 

Obama may win on pessimism (7 Feb 2012)

 

THE BEAR'S LAIR : The government bubble (7 Feb 2012)

more »

 


Site feed Updated: 2012-Feb-07 15:00