sled is an embedded database that provides an API similar to a threadsafe BTreeMap<[u8], [u8]>. It is designed to offer ACID transactions, zero-copy reads, atomic operations, and much more, making it suitable for various applications requiring embedded databases.
let tree = sled::open("/tmp/welcome-to-sled")?;// insert and get, similar to std's BTreeMaplet old_value = tree.insert("key", "value")?;assert_eq!( tree.get(&"key")?, Some(sled::IVec::from("value")),);// range queriesfor kv_result in tree.range("key_1".."key_9") {}// deletionlet old_value = tree.remove(&"key")?;// atomic compare and swaptree.compare_and_swap( "key", Some("current_value"), Some("new_value"),)?;// block until all operations are stable on disktree.flush()?;
sled offers LSM tree-like write performance combined with B+ tree-like read performance. It can handle over a billion operations in under a minute on 16 cores with a mix of read and write operations.
sled is built on a lock-free tree structure atop a lock-free pagecache, designed for high concurrency and efficiency. It employs modern b-tree techniques like prefix encoding and suffix truncation to reduce storage costs.