The Importance of Bits

With their abundant availability both in volatile and permanent storage (i.e., RAM and hard-disks), sometimes I think the value of bits is lost on more recent developers, especially those that write in a very high-level language, like, say, PHP. The past few weeks I’ve been working very closely with some data analysts in our company — in particular, I’ve been compiling some very large tables (think nearly 1 billion rows per month) into “views” (technically, they’re completely new tables) that are much more manageable.

Tonight, mostly as an exercise in futility, I began looking at some of the foreign keys stored in the gargantuan tables. One of them in particular links to a table that currently contains (oddly enough) 256 rows. It grows very, very slowly. Currently the column is a long integer: 4 bytes. Imagine for a minute that we replaced that with what MySQL calls a small integer, or 2 bytes. Last month’s table was in the neighborhood of 900,000,000 rows, times 2, divided by 1024… That’s something just shy of 2 GIGAbytes that we’ve saved. (Never mind that there are about 4 other foreign keys this could also be applied to).

Every byte adds up, folks. Save ’em while you can.

(Some might call this inconvenient math. I’m not quite that unscrupulous.)

2 Comments so far

  1. Mr. T on January 7th, 2008

    I’m old school so needless wasting of bits, bytes and words drives me crazy. Now I’m all in favor of leaving room for full year and not trying to get by with the last two digits. I went though a Y2K problem back in the 80s so I know what is involved. But using a quadword with a single word will do or using a whole byte (or worse word) when a bit will do (bit flags anyone?) is just wastefull. And it is not just disk space – don’t get me started about bloated applications using up memory!

  2. Matt on January 8th, 2008

    I still have the “old school” expectations of space, even though I’m probably not an “old school” programmer. It blows my mind that operating systems need more than a CD-ROM of space–heck, I remember using Linux distros that fit on a floppy. Not a great desktop environment there, but still, 700MB? And web browsers? A meg of RAM is a good chunk of space. I’m sure it’s much more complex, but if you asked me how much memory a web browser needed, I’d give you 2 meg — and most of it would be for cache.

    (“No, Bill, this isn’t an inconvenient time… Yes, Bill, I get it…”)

Leave a Reply