react-native-lmdb
Installation
npm install react-native-lmdb
cd ios && pod install
Usage
import { open } from 'react-native-lmdb';
// Define the largest size of the db (100mb in this case)
const mapSize = 1024 * 1024 * 100;
const { put, get, del } = open('mydb.mdb', mapSize);
put('key1', 'value1');
put('key2', 'value2');
console.log(get('key1'));
console.log(get('key2'));
del('key1');
del('key2');
Motivation
MMKV is a great tool but isn't designed for vast amounts of data.
When setting and getting 10_000 large strings:
DB | Empty | Run 1 | Run 2 | Run 3 |
---|---|---|---|---|
mmkv | 16kb | 33.6mb | 67.1mb | 67.1mb |
lmdb | 33kb | 38.3mb | 38.3mb | 38.3mb |
// @TODO - check db sizes on devices
SQLite can handle vast amounts of data but is async thus increases complexity and introduces possible race conditions.
LMDB is mature, synchronous, and can handle anything you throw at it. 💪
Goals of this Project
- Simple API
- Performance over features
Benchmarks
NOTES: these numbers might not represent current state. I am still in the process of profiling and optimising.
iOS (Simulator)
|
iOS (iPhone 7)
|
Android (Emulator)
|
Android (Pixel 6a)
|
We can conclude:
- mmkv is fast to read
- mmkv is fast to write
- lmdb to fast to read
- lmdb is (potentially very) slow to write depending on device, but can write fast when using a transaction (txn).
Credits
- Thanks to sysmas for open sourcing lmdb.
- Thanks to drycpp/lmdb++ & hoytech/lmdb++ for the useful c++ wrapper.
Donate
If you find LMDB useful please consider supporting the OpenLDAP foundation: https://www.openldap.org/foundation/
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library