walpack 0.1.0
walpack: ^0.1.0 copied to clipboard
High-performance, crash-safe, single-file binary container with chunked storage and append-only write-ahead log (WAL) for Dart.
walpack #
Crash-safe, single-file binary container library for Dart. Pure Dart · Zero Native/FFI · VM, AOT, Flutter, Web & WASM
Built on pro_binary, walpack pairs an immutable chunked Base Snapshot (WLPK v1) with an append-only CRC32-C Write-Ahead Log (WAL) for sub-millisecond cold opens, lazy chunk reads, $O(1)$ saves, binary-search indexes, and multi-process live synchronization.
Why walpack? #
- One Clean File on Disk: Base Snapshot, sorted Base TOC + Base Index, and append-only WAL live inside a single portable
.wpkfile. - Instant Lazy Opens & Coalesced Reads: Cold open skips large blobs until requested;
readChunks()and index queries coalesce nearby reads into contiguous transfers, backed by an optionalreadCacheBytesLRU cache. - $O(1)$ Crash-Safe Saves: Commits append one scatter-gather CRC32-C-sealed frame (
crc32cCombine+ automatic rollback on partial writes + Copy-on-Writecompact()via OSrename()). - Native Sorted & Secondary Indexes: Built-in $O(\log N + K)$
keysWithPrefix(),keysInRange(),queryIntIndex(), andqueryStringIndex()kept live across compacted snapshots and WAL deltas. - Fast Pure-Dart Codecs & Checksums: Slicing-by-8 CRC32-C (
~1.12 GiB/s), 32-bit stripe XXH32 (~3.1 GiB/s), pure-Dart LZ4 block compression (~1.3 GiB/sdecode), plus native ZLib ondart:io. - Multi-Process Ready: Lock-generation tracking (
sync()), Optimistic Concurrency Control (expectedSeq->CommitConflict), and pluggable backends (IoStorageBackend,MemoryStorageBackend,FaultInjectionBackend).
Install #
dependencies:
walpack: ^0.1.0
Quick Start #
import 'dart:typed_data';
import 'package:walpack/walpack.dart';
Future<void> main() async {
final pack = await WalPack.openFile(
'project.wpk',
options: const WalPackOptions(appId: 'PICO'),
);
await pack.commit((tx) {
tx
..putChunkWith(
'page/home',
(w) => w
..writeVarString('Home Screen')
..writeVarUint(42),
intIndexes: const {'order': 1},
)
..putBlobIfAbsent('asset/logo', Uint8List.fromList([0x89, 0x50, 0x4E, 0x47]))
..appendOpWith(opType: 1, encode: (w) => w.writeVarString('init'));
});
final ordered = pack.queryIntIndex('order', min: 1, max: 10); // ['page/home']
final home = await pack.readChunkWith(
ordered.first,
(r) => (title: r.readVarString(), nodes: r.readVarUint()),
);
print(home); // (title: Home Screen, nodes: 42)
await pack.compact();
await pack.close();
}
Performance Highlights (Dart AOT) #
Measured on Linux x86_64 with dart compile exe — full results and tuning guide in doc/performance.md:
| Benchmark | Result | Notes |
|---|---|---|
Cold open 50.0 MiB disk pack |
0.171 ms |
Reads header, TOC & WAL index only |
WAL 64B op append (Memory / Disk NoLock) |
2.06 µs / 4.50 µs |
~222k–485k tx/s uncontended |
Multi-handle sync() (up-to-date check) |
7.08 µs |
Lock-generation check, no data reopen |
Lazy disk chunk read (1 MiB, CRC32-C) |
1,103 µs |
907 MiB/s verified sequential transfer |
| CRC32-C / XXH32 (pure Dart, 1 MiB) | 1,124 MiB/s / 3,098 MiB/s |
Slicing-by-8 + algebraic crc32cCombine |
CoW compact() (25 MiB pass-through + swap) |
32.02 ms |
781 MiB/s without decompressing chunks |
Documentation & Examples #
| Guide / Example | Topics Covered |
|---|---|
| Getting Started & Recipes | Installation, pro_binary chunks, secondary indexes, sync(), OCC, compaction |
| Architecture & Concurrency | Snapshots + WAL, read-coalescing, IoMode, POSIX fcntl & Windows locks |
Binary Format (WLPK v1) |
Superblock, sorted TOC & Base Index, WAL CommitFrame, WalPackLimits |
| Performance & Tuning | Full AOT benchmarks, caching, codecs, locking & memory characteristics |
| Runnable Examples | main.dart · multiprocess_example.dart · custom_backend_example.dart |
License #
MIT License — see LICENSE.