tervyx

    Zero-dependency, cross-backend, modular high-performance core extension library for MoonBit: cache-friendly data structures, algorithms, and utilities.

    collections
    data-structures
    algorithms
    utilities
    performance
    simd
    systems
    zero-dependency
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    28 minutes ago
    Downloads
    1

    No dependencies

    #ihb2032/tervyx

    Zero-dependency, independently-importable high-performance core extension library for MoonBit 1.0 across wasm, wasm-gc, js, and native, combining battle-tested designs from C++ (Abseil / Folly / LLVM / Boost / C++23 std::flat_map), Rust (memchr / slotmap / extract_if), .NET (SearchValues), OCaml (Jane Street Core change / update), Go (Append-into-dst buffer reuse), Java (Agrona / fastutil unboxed IntMap), and MoonBit's native Why3/Z3 formal verification (moon prove).

    #Installation

    Add ihb2032/tervyx to your MoonBit project:

    moon add ihb2032/tervyx

    Import individual sub-packages in your moon.pkg so downstream builds pay for the containers and utilities you use, with zero transitive third-party dependencies:

    import {
    "ihb2032/tervyx/flat_map",
    "ihb2032/tervyx/memscan",
    "ihb2032/tervyx/slot_map",
    }

    #Packages

    PackageHighlightsDesign & 4-Backend Benchmarks
    ihb2032/tervyx/hash64-bit XXH64 (hash_bytes, hash_string, mix64) & streaming RapidHasherdocs/packages/hash.md
    ihb2032/tervyx/memscan32-byte unrolled V128 SIMD find_byte, rfind_byte, find_byte2/3, find_bytes, is_valid_ascii, multi-strategy SearchValuesdocs/packages/memscan.md
    ihb2032/tervyx/small_vecInline SmallVec4, SmallVec8, fixed-cap StaticVec, inline-64-bit SmallBitSetdocs/packages/small_vec.md
    ihb2032/tervyx/slot_map#valtype Key, flat SoA generational SlotMap, DenseSlotMap, SecondaryMapdocs/packages/slot_map.md
    ihb2032/tervyx/flat_mapSingle-probe SwissTable FlatHashMap / FlatHashSet, unboxed IntMap, contiguous SortedFlatMapdocs/packages/flat_map.md
    ihb2032/tervyx/btreeHigh-fanout cache-friendly BTreeMap & BTreeSet (single-traversal change, flat-cursor iter/range, range_into)docs/packages/btree.md

    #Quick Examples

    // SwissTable + OCaml single-lookup atomic `change` + unboxed `IntMap`
    let counts = @flat_map.IntMap([(1, 10), (2, 20)])
    counts.change(1, cur => Some(cur.unwrap_or(0) + 5))

    // Multi-strategy SIMD byte-set scanning (.NET SearchValues) + Go buffer reuse
    let delims = @memscan.SearchValues(b",;\r\n")
    let first = delims.find_any(b"key=value;next")
    let hits : Array[Int32] = []
    @memscan.find_all_byte_into(b"a,b,c", b',', hits)

    // ABA-safe generational arena
    let entities : @slot_map.SlotMap[String] = SlotMap()
    let hero = entities.insert("hero")
    ignore(entities.update(hero, name => name + "!"))

    #4-Backend Performance Highlights

    Measured in --release mode on an AMD Ryzen 7 7840HS (WSL2, MoonBit v1.0.0-rc1+3c0520448; see docs/README.md and each package handbook for complete cross-backend tables):

    • memscan (4096 B): is_valid_ascii reaches 94.32 ns on native (~43.4 GB/s, 9.6× vs scalar) and 959.55 ns on wasm-gc (2.11×); find_byte reaches 106.64 ns on native (~38.4 GB/s, 8.4×), 144.30 ns on wasm (11.8×), 1.10 µs on wasm-gc (1.58×), and 1.19 µs on js (1.57×); find_bytes runs in 211.57 ns on native, 1.30 µs on wasm-gc, and 1.20 µs on js.
    • hash (4096 B): Direct-offset XXH64 reaches 255.85 ns on wasm (~16.0 GB/s, 5.28× vs core 32-bit Hasher), 312.57 ns on native (~13.1 GB/s, 4.19×), 1.40 µs on wasm-gc (1.18×), and 4.41 µs on js (4.34× faster via zero-BigInt 32-bit (lo, hi) XXH64).
    • flat_map: Single-probe unboxed IntMap beats core/hashmap across the 4 targets on both 1000-key insert (wasm 2.94×, native 1.47×, wasm-gc 1.22×, js 1.06×) and hit (native 1.99 µs, js 2.73 µs, wasm-gc 3.15 µs, wasm 5.22 µs); SortedFlatMap (n = 128) beats core/sorted_map on wasm (1.73×) and native (1.27×).
    • btree: BTreeMap sequential 1000-key build beats core/sorted_map across the 4 targets (2.11×–8.49×), borrowed tail-recursive lookup reaches 17.78 µs on wasm (3.29× vs core/sorted_map) and 9.62 µs on wasm-gc, and flat-cursor iteration beats core/sorted_map on native (1.39×), wasm (1.09×), and wasm-gc (1.05×).
    • slot_map: Flat FixedArray SoA SlotMap::get beats core/Map across the 4 targets (1.52×–3.46×, down to 732.22 ns on native), and DenseSlotMap fragmented iteration leads by 1.40×–7.18×.
    • small_vec: Both SmallVec4 and SmallVec8 beat Array across the 4 targets; SmallBitSet inline operations beat core/Map by 24.7× on js (18.63 ns via zero-BigInt 32-bit split), 23.5× on native (18.14 ns), 11.2× on wasm, and 7.92× on wasm-gc.

    #Formal Verification & Quality Gates

    Core algorithmic invariants that fit moonc-prove 1.0.0-rc1 (generic K : Compare binary search in BTreeMap nodes and SortedFlatMap, SwissTable 7/8 probe termination and doubling growth, SmallBitSet word/bit addressing, SlotMap Key::null/is_null/version contracts, B-Tree INV2 split balance, and memscan inner byte-range verification) are machine-checked by Why3 + Z3 4.12.6 directly inside the owning packages (memscan, small_vec, slot_map, flat_map, and btree, each with proof_enabled = true and a colocated proof.mbtp) via moon prove on Linux CI (17 proved goals).

    Enable the local pre-commit hook:

    git config core.hooksPath .githooks

    Run the local quality gate:

    moon check --deny-warn moon fmt --check moon info moon prove moon test --target all moon coverage analyze moon bench --target all --release

    #License

    Apache-2.0