woltapp / blurhash

A very compact representation of a placeholder for an image.
https://blurha.sh
MIT License
15.67k stars 353 forks source link

Make the base 83 encoding optional. #93

Open ioistired opened 3 years ago

ioistired commented 3 years ago

Suppose I want to store 80,000 pre-blurred images in my database. LjIY5?00?bIUofWBWBM{WBofWBj[ is a sample 4×3 blurHash, and is 28 bytes (224 bits) long. Suppose I use a fixed-width data type in my database, so I don't need the first character of the string which encodes the length. If we remove the first character and encode the same blurHash in its equivalent raw bytes, we need only ~10 bytes (73 bits) to encode the hash, saving 1.5 MB on disk for 80,000 images. That may seem like a micro-optimization, especially in an RDBMS which may duplicate data in indexes. You could say I'm just allergic to plaintext formats when a more compact representation would do, and you'd be right :) I still think there's value in this approach though.

jagerman commented 1 year ago

There definitely is merit in this: base83 is imposing the (severe) limitations of JSON binary encoding onto the user of the library, when the user of the library might be perfectly capable of representing binary data as binary data (as in the OP's case). Helpers for JSON/HTML compatibility are fine, but right now they are forced on everyone rather than only being forced on people who are themselves forced to deal with JSON's limitations.