Transparent LZ4 compression for Anchor account fields.
Store less data, pay less rent.
densol lets you compress a Vec<u8> field inside any Anchor account with a single
attribute. The compression runs fully on-chain using LZ4 via
lz4_flex,
which keeps its hash table on the stack (16 KB) and stays within the SBF VM's 32 KB heap limit.
I built this to answer a question I couldn't find answered anywhere: is on-chain compression actually worth the extra compute units? So I measured it.
# Cargo.toml
densol = "0.1"
use densol::Lz4 as Strategy;
use densol::Compress;
#[account]
#[derive(Compress)]
pub struct MyAccount {
#[compress]
pub data: Vec<u8>,
}
// Generated methods:
// account.set_data(&raw_bytes)?; // compress + store
// account.get_data()?; // load + decompress
Strategy alias is how the derive macro knows which algorithm to use.
Swap it for a different type implementing Compressor to change algorithms at compile time.
densol = { version = "0.1", default-features = false, features = ["lz4", "discriminant"] }
lz4 — LZ4 strategy via lz4_flex ·
discriminant — 1-byte algorithm tag prepended to output ·
derive — re-exports #[derive(Compress)] ·
std — implements std::error::Error for errors