MCPcopy Index your code
hub / github.com/Abso1ut3Zer0/nexus

github.com/Abso1ut3Zer0/nexus @nexus-stats-v6.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release nexus-stats-v6.0.1 ↗ · + Follow
13,893 symbols 59,868 edges 676 files 1,680 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Nexus

Low-latency primitives and runtime for building high-performance systems.

Philosophy

These crates are born from years of building trading infrastructure, where certain patterns become clear: most systems don't need unbounded queues, dynamic allocation, or multi-producer flexibility. They need predictable, bounded, specialized primitives that do one thing well and never surprise you at runtime.

The core philosophy is predictability over generality:

  • SPSC over MPMC — When you have one producer and one consumer, don't pay for synchronization you don't need
  • Pre-allocation over dynamic growth — Allocate at startup, never on the hot path
  • Bounded over unbounded — Know your capacity, reject rather than allocate
  • Specialization over abstraction — A conflation slot isn't a queue of size 1, it's a different thing entirely

The goal isn't "fastest in microbenchmarks." It's consistent, low-latency behavior under real workloads — minimizing tail latency, avoiding syscalls, eliminating allocation jitter.

Each crate is small, focused, and honest about its constraints. No kitchen sinks.

Architecture

┌─────────────────────────────────────────────────────────┐
│                        *Runtime*                        │
│             rt · async-rt* · timer · + tokio            │
├─────────────────────────────────────────────────────────┤
│                       *Analytics*                       │
│                   stats-* · inference                   │
├─────────────────────────────────────────────────────────┤
│                       *Networking*                      │
│                     net · async-net                     │
├─────────────────────────────────────────────────────────┤
│                      *Concurrency*                      │
│         queue · channel · slot · notify · logbuf        │
├─────────────────────────────────────────────────────────┤
│                 *Collections & Flow Control*            │
│                    collections · rate                   │
├─────────────────────────────────────────────────────────┤
│                        *Storage*                        │
│                  slab · pool · smartptr                 │
├─────────────────────────────────────────────────────────┤
│                         *Types*                         │
│               bits · ascii · id · decimal               │
└─────────────────────────────────────────────────────────┘

* async-rt is experimental — use tokio for production async workloads

Crates

Types & Encoding

Crate Description
nexus-bits Bit-packed integer newtypes via derive macros. Structs, tagged enums, IntEnum for discriminants. Zero-cost #[repr(transparent)] with compile-time validation.
nexus-ascii Fixed-capacity ASCII strings. Stack-allocated, immutable, with precomputed 48-bit XXH3 hash. Identity-hashable via nohash feature for zero-cost lookups.
nexus-id High-performance ID generators: Snowflake, UUID v4/v7, ULID. SIMD-accelerated hex encode/decode. Fibonacci mixing for identity hashers.
nexus-decimal Fixed-point decimal arithmetic with compile-time precision. Decimal<i64, 8> for prices, Decimal<i128, 12> for DeFi. Const fn, no_std, zero allocation. Financial methods: midpoint, tick rounding, basis points. Chunked magic division avoids __divti3.

Storage & Allocation

Crate Description
nexus-slab Manual memory management with SLUB-style slab allocation. bounded::Slab (fixed capacity) and unbounded::Slab (growable via chunks). rc feature adds RcSlot with borrow guards for shared ownership. 1 cycle alloc, sub-cycle free (benchmarks).
nexus-pool Object pools with RAII guards. Single-threaded BoundedPool and thread-safe sync::Pool (one acquirer, any returner).
nexus-smartptr Inline and flexible smart pointers for type-erased storage. FlatBox (fixed inline), FlexBox (inline or heap). Avoids boxing for small handler types.

Collections

Crate Description
nexus-collections Slab-backed intrusive collections. O(1) linked lists, O(log n) heaps, red-black trees, B-trees. External allocation via nexus-slab — user owns the slab, collection wires pointers. 2-3 cycle list operations, 15 cycle tree lookups (benchmarks).

Flow Control

Crate Description
nexus-rate Rate limiting. GCRA, token bucket, sliding window counter. Single-threaded and thread-safe variants. Weighted requests. ~2-4 cycle hot path (benchmarks).

Concurrency & Communication

Crate Description
nexus-queue Lock-free SPSC, MPSC, and SPMC ring buffers with per-slot lap counters. Index-based (NUMA-friendly) and slot-based (shared-L3 friendly) implementations.
nexus-channel Blocking SPSC channel built on nexus-queue. Three-phase backoff (spin → yield → park) minimizes syscalls under load.
nexus-slot Single-value conflation slot. Writer always overwrites, reader gets latest value exactly once. For "latest wins" patterns like market data snapshots.
nexus-notify Cross-thread event queue with conflation and FIFO delivery. Non-blocking event_queue and blocking event_channel. Dedup flags + MPSC ring buffer — O(limit) poll, ~5 cycles/token (benchmarks).
nexus-logbuf Bounded SPSC and MPSC byte ring buffers. Claim-based API for variable-length messages. The hot-path primitive for getting data off the event loop without syscalls.

Networking

Crate Description
nexus-net Low-latency networking primitives: buffers (ReadBuf, WriteBuf), TLS codec (rustls), wire abstractions (WireStream, ParserSink), MaybeTls transport. Foundation for nexus-web and nexus-async-web.
nexus-web Sans-IO WebSocket (RFC 6455), HTTP/1.1, and REST primitives. Zero-copy, SIMD-accelerated. 3x faster than tungstenite, 3x faster than reqwest. Typestate request builder, chunked transfer encoding, connection poisoning. 517/517 Autobahn + 16/16 httpbin conformance.
nexus-async-web Async adapters for nexus-web. Tokio-compatible. WebSocket WsReader/WsWriter, HTTP HttpConnection<S>, and ClientPool/AtomicClientPool with self-healing reconnect. try_acquire (fast path) and acquire (patient path with backoff). 3.5x faster than tokio-tungstenite (benchmarks).

Runtime

Crate Description
nexus-rt Event-driven runtime. World/ECS resource model, handler dispatch, pipelines, DAGs, driver system, clock. No async/await — explicit poll loops with monomorphized zero-cost dispatch.
nexus-async-rt Experimental. Single-threaded async executor. Slab-allocated tasks, zero-allocation waker vtable, mio-backed IO driver, timer wheel, signal handling. Not under active development — use tokio for production async workloads.
nexus-timer Hierarchical timer wheel with O(1) insert and cancel. No-cascade design inspired by the Linux kernel. Slab-backed, zero allocation after init.

Streaming Statistics

Fixed-memory, zero-allocation streaming analytics. All types are O(1) per update, designed for hot-path integration. The nexus-stats umbrella crate re-exports everything; the subcrates allow fine-grained dependency control.

Crate Description
nexus-stats Umbrella crate — re-exports all subcrates below under a unified namespace.
nexus-stats-core Foundation types and core algorithms. Welford moments, EMA/AsymEMA, covariance, drawdown, min/max, percentile (P²), normalization (ZScore, MinMax, Quantile), microstructure (Amihud, KyleLambda, RollSpread, Bipower, TwoScaleRv), monitoring (CoDel, Jitter, Liveness, EventRate, Hawkes intensity).
nexus-stats-smoothing Advanced smoothing. KAMA, Holt double exponential, Spring (critically damped), Kalman1d, Hampel filter, HuberEMA, ConditionalEMA, WindowedMedian.
nexus-stats-detection Change detection and signal analysis. CUSUM, MOSUM, BOCPD, Shiryaev-Roberts, ADWIN, Page-Hinkley, distribution shift/drift, adaptive threshold, trend alert, entropy, transfer entropy, predictive information bound, autocorrelation, cross-correlation.
nexus-stats-regression Online regression, learning, and estimation. Linear/polynomial/power/log/exponential regression (OLS + EW), Huber-robust regression, RLS/LMS/NLMS adaptive filters, logistic regression, online K-means, Kalman 2d/3d, online gradient descent, AdaGrad, Adam.
nexus-stats-control Control and frequency primitives. Dead band, hysteresis, debounce, level crossing, peak detector, bool window, TopK, proportion tracking, decay accumulator.

Inference

Real-time CPU inference for small, pre-trained models. Train in Python (PyTorch, LightGBM), load once via from_parts or SafeTensors, predict millions of times. Sub-microsecond latency, zero allocation after construction, SIMD-accelerated (SSE2/AVX2/AVX-512).

Crate Description
nexus-inference 12 model types across stateless and stateful inference. Stateless: GBDT (branchless traversal, NaN-aware, LightGBM-compatible), MLP (SIMD-tiled matmul, LayerNorm, 8 activations), LUT (O(1) lookup table), BNN (binary neural network, XNOR+popcount), QuantizedMLP (i8 weights, i32 accumulation). Stateful: LSTM, GRU, stacked LSTM/GRU, linear state-space model (S4/S4D), causal 1D convolution, temporal convolutional network (TCN). Stateless models use interior mutability (&self) for zero-contention sharing; stateful models carry hidden state between calls. SafeTensors and LightGBM JSON loaders.

Design Principles

No allocation on the hot path

Every crate that manages memory supports pre-allocation. You pay the cost at startup, not when processing the millionth message.

Honest constraints

SPSC means SPSC. Don't sneak in an extra producer and expect it to work. The constraints enable the performance.

Benchmark what matters

Synthetic throughput is easy to game. We optimize for realistic workloads: ping-pong latency, p99/p999 tail latency, jitter under load. See individual crate BENCHMARKS.md files for methodology and results.

Minimal dependencies

These are foundational crates. Dependency trees are kept small and intentional.

Benchmark Conditions

Performance numbers are measured on an Intel Core Ultra 7 165U (12C/14T, 12MB L3) running Arch Linux with rustc 1.94.0. Comparative numbers (speedup ratios) are measured with turbo boost disabled and cores pinned via taskset; finalized cycle counts are with turbo boost enabled. Results vary by hardware — each crate's BENCHMARKS.md records the specific machine, toolchain, comparison-crate versions, and reproduction steps.

Platform Support

  • Linux — Primary target, fully supported
  • macOS — Supported
  • Windows — Experimental where noted, typically behind feature flags

Contributing

Please read CONTRIBUTING.md before submitting changes.

The short version: we build specialized primitives, not general-purpose ones. Different constraints mean different problems, and different problems deserve different solutions. If you're proposing a feature, be ready to justify why it belongs in a tuned, minimal implementation.

We also have specific benchmarking standards — cycles not time, turbo boost disabled, cores pinned, jitter eliminated. Details in the contributing guide.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 8,541
Method 3,902
Class 1,231
Enum 126
Interface 93

Languages

Rust99%
Python1%

Modules by API surface

nexus-rt/tests/compile_tests.rs433 symbols
nexus-ascii/src/string.rs328 symbols
nexus-rt/src/pipeline.rs266 symbols
nexus-fix-codec/src/types.rs231 symbols
nexus-ascii/src/flat_string.rs163 symbols
nexus-ascii/src/text.rs150 symbols
nexus-rt/src/dag.rs146 symbols
nexus-rt/src/codegen_audit/pipeline.rs124 symbols
nexus-bits/tests/derive_struct.rs117 symbols
nexus-web/src/ws/frame_reader.rs110 symbols
nexus-rt/src/reactor.rs106 symbols
nexus-rt/src/world.rs105 symbols

For agents

$ claude mcp add nexus \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page