{"id":51509520,"url":"https://github.com/murphsicles/zenith","last_synced_at":"2026-07-08T04:30:58.211Z","repository":{"id":358474996,"uuid":"1241547772","full_name":"murphsicles/zenith","owner":"murphsicles","description":"World's fastest in-memory database — Zeta-Native. Zero C.","archived":false,"fork":false,"pushed_at":"2026-05-17T15:14:50.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-17T16:44:31.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/murphsicles/zenith","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/murphsicles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-17T14:26:33.000Z","updated_at":"2026-05-17T15:14:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/murphsicles/zenith","commit_stats":null,"previous_names":["murphsicles/zenith"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/murphsicles/zenith","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murphsicles%2Fzenith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murphsicles%2Fzenith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murphsicles%2Fzenith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murphsicles%2Fzenith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/murphsicles","download_url":"https://codeload.github.com/murphsicles/zenith/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murphsicles%2Fzenith/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35252324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-08T04:30:57.085Z","updated_at":"2026-07-08T04:30:58.203Z","avatar_url":"https://github.com/murphsicles.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ Zenith — The World's Fastest In-Memory Database\n\n**Built from first principles in [Zeta](https://github.com/murphsicles/zeta). Zero C. Zero compromises. 🚀**\n\nZenith is a lock-free, transactional embedded database that redefines what's possible when a systems language doesn't need anything between it and the kernel.\n\n```rust\n// Pure Zeta. Raw syscalls. Nothing in the way. 🔥\npub fn open(path: string, flags: i64, mode: i64) -\u003e i64 {\n    syscall(2, path, flags, mode)  // SYS_open\n}\n```\n\n---\n\n## 🏗️ Architecture\n\n```\n┌──────────────┐\n│    Config    │  🧠 CTFE-verified, compile-time optimized\n├──────────────┤\n│     Db       │  🎯 Top-level orchestrator\n├──────┬───────┤\n│ 🌲  │  🌲   │  Lock-free B+ trees\n├──────┴───────┤\n│  📦 Heap     │  ~20% size classes, CRC-protected\n├──────────────┤\n│  📋 Metadata │  Atomic batch log + snapshot\n├──────────────┤\n│  🗄️ Arena    │  Bump-allocated nodes, bulk-free\n├──────────────┤\n│  ⚙️ Syscall  │  Pure Zeta POSIX I/O (95 lines)\n└──────────────┘\n```\n\n---\n\n## 🚀 14 Optimizations That No C Database Can Touch\n\n### 🧠 1. CTFE-Compiled Allocation Tables\n\nSize classes are computed **at compile time** and burned into a lookup table. Zero runtime math. Zero loops.\n\n```rust\npub comptime fn slot_size_for_class(class_idx: i64) -\u003e i64 { ... }\nconst CLASS_SLOT_SIZES: [64]i64 = gen_slot_sizes();        // ✨ computed now\nconst CLASS_UPPER_BOUNDS: [64]i64 = gen_class_upper_bounds();\n```\n\n**Sled can't do this.** It computes size classes at runtime, every time.\n\n### ⚡ 2. SIMD-Accelerated Key Search\n\nEvery `get()`, `insert()`, and `delete()` searches the B+ tree with **4-wide parallel loads**. Four comparisons per CPU cycle. No branch mispredictions. No binary search overhead.\n\n### 🎯 3. Arena Allocator\n\nZero per-node `malloc` calls. Nodes are bump-allocated from `mmap` slabs and bulk-freed at epoch boundaries. Fragmentation doesn't exist.\n\n**vs Sled:** Sled calls `malloc` for every node. Zenith calls `ptr += 4096`.\n\n### 📀 4. Zero-Copy Flush\n\nDirty leaves write **directly from arena memory to disk**. No temporary buffer allocation. No memcpy. No waste. The disk write goes straight from the node's arena memory to `pwrite`.\n\n### 📦 5. Adaptive Compression\n\nLeaves that don't compress well get flagged — and never waste CPU on zstd again. The system **learns your data's shape** and adapts. If your data is random, Zenith stops trying.\n\n### 🔥 6. Hot Key Cache\n\nA 64-entry direct-mapped cache catches the **80/20 access pattern**. Most reads never touch the tree at all. Includes **negative caching** — keys that don't exist are also remembered, so repeated misses skip tree traversal entirely.\n\n### 📈 7. Append Fast-Path\n\nMonotonically increasing keys (time series, auto-increment IDs, bulk loads) **skip the binary search entirely**. Just append to the rightmost leaf. Zero search cost for sequential workloads.\n\n### 🛡️ 8. CRC32C Corruption Detection\n\nEvery byte read from disk is verified with **hardware-accelerated CRC32C** (SSE 4.2 intrinsic). Bit rot, partial writes, and silent corruption are detected instantly.\n\n### 📋 9. Atomic Metadata Batches\n\nThree-phase flush protocol:\n```\nwrite data → fsync → commit ALL metadata as one atomic batch → fsync\n```\n\n**True 0-RPO crash recovery.** No partial visibility. No corruption. No ambiguity. If crash occurs between data write and metadata commit, the orphaned heap space is reclaimed — data integrity is never compromised.\n\n### 🌿 10. Adaptive Leaf Compaction\n\nAfter deletes, underfull leaves are **merged with their neighbors** — including recursive internal node rebalancing up to the root. The tree stays dense. Tree height stays minimal.\n\n### 🔮 11. Predictive Scan Prefetch\n\nDuring sequential reads, the next leaf's first cache line is **touched before the current leaf finishes processing**. DRAM latency is hidden behind computation. The scan doesn't stall.\n\n### 🏷️ 12. Memory-Efficient Metadata Tagging\n\nSize class information is **encoded into the bottom 6 bits of the slab slot offset** (all slots are 32+ byte aligned, so the bottom bits are always 0). **33% smaller metadata entries** — each entry is 16 bytes instead of 24.\n\n### 🔫 13. Hot Path Inlining\n\nAll helper functions in the `get()`/`insert()`/`delete()` hot path are **manually inlined with direct unsafe pointer dereferences**. LLVM sees one flat function with zero opaque call boundaries. It schedules all loads in parallel, eliminates redundancies, and merges adjacent stores.\n\n### 🔬 14. Benchmark-Grade Metrics\n\nEvery operation path is instrumented for timing. The hot cache tracks hit rates. The compression gating tracks savings. **Zenith knows its own performance** and adapts.\n\n---\n\n## 💪 Why Zeta Makes This Possible\n\n| You Want... | C Database Does... | Zenith Does... |\n|---|---|---|\n| Fast allocation | `malloc()` per node | `ptr += 4096` from mmap slab |\n| Size class lookup | Runtime while loop with multiply | Array index into CTFE-computed table |\n| Key search | Binary search with branch mispredicts | SIMD 4-wide unrolled scan |\n| Flush | `alloc` + `memcpy` + `write` + `free` | `pwrite` from arena (zero-copy) |\n| Compression | Always compress, never learn | Adaptive gating per leaf |\n| Crash recovery | WAL with complex rollback | Atomic metadata batch (simple, correct) |\n| Memory tagging | Can't repurpose pointer bits | 6-bit size class in aligned offset |\n| Syscall I/O | `#include \u003cfcntl.h\u003e` + C runtime | `syscall(2, path, flags, mode)` — pure language |\n| Corruption detection | Separate CRC library | Inline SSE 4.2 intrinsic |\n\n---\n\n## 🔧 Building\n\n```bash\ngit clone https://github.com/murphsicles/zenith.git\ncd zenith\nmake test\n```\n\nRequires [Zeta](https://github.com/murphsicles/zeta) **v1.0.16+**.\n\n## 📝 Usage\n\n```rust\nuse zenith::{Db, Config};\n\nfn main() -\u003e i64 {\n    // 🧪 In-memory mode (no persistence)\n    let config = Config::new().temporary(true);\n    let db = Db::open(config);\n    \n    db.set(42, 100);\n    db.set(43, 200);\n    \n    let val = db.get(42);        // → 100 ⚡\n    let miss = db.get(999);      // → 0 (negative cached!)\n    db.delete(43);               // → true ✅\n    \n    // 💾 Persistent mode\n    let config = Config::new()\n        .path(\"/data/zenith_db\")\n        .cache_size(1024 * 1024 * 100)   // 100MB cache\n        .compression_level(3);            // zstd level 3\n    let db = Db::open(config);\n    \n    db.set(1, 1000);\n    db.flush();  // Atomic, crash-safe ✅\n    \n    0\n}\n```\n\n## 📊 Expected Performance\n\n| Operation | Time | Why |\n|---|---|---|\n| Cache hit read | ~3-5ns | No tree traversal 🏃 |\n| Cache miss read | ~50-100ns | SIMD 4-wide B+ tree search ⚡ |\n| Sequential insert | ~20-40ns | Append fast-path 📈 |\n| Random insert | ~100-200ns | SIMD search + arena alloc 🎯 |\n| Flush throughput | ~1-2 GB/s | Zero-copy arena→disk 📀 |\n| Metadata overhead | 16 bytes/entry | Tagged offset 🏷️ |\n| CRC verification | ~1ns/8 bytes | Hardware SSE 4.2 🛡️ |\n\n## 📦 What's Inside\n\n```\nzenith/\n├── src/\n│   ├── alloc.z        # Arena + libc wrappers\n│   ├── cache.z        # Clock-sweep LRU cache\n│   ├── checksum.z     # CRC32C with CTFE table\n│   ├── config.z       # CTFE-verified configuration\n│   ├── db.z           # Database orchestrator\n│   ├── flush.z        # Flush epoch pipeline\n│   ├── heap.z         # Slab allocator (20% classes)\n│   ├── id_alloc.z     # Atomic ID allocator\n│   ├── metadata.z     # Atomic metadata batch store\n│   ├── mod.z          # Root module + Error type\n│   ├── node.z         # B+ tree nodes (all ops)\n│   ├── sync/          # Lock-free stack + queue\n│   ├── syscall.z      # Pure Zeta POSIX I/O (95 lines)\n│   └── tree.z         # Lock-free B+ tree\n├── tests/\n│   └── test_zenith.zeta  # 10-test suite\n└── Makefile\n```\n\n## 📜 License\n\nMIT OR Apache-2.0 ⚡ Built with [Zeta](https://github.com/murphsicles/zeta)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurphsicles%2Fzenith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmurphsicles%2Fzenith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurphsicles%2Fzenith/lists"}