Pure C, static musl binaries, ~2MB RSS, <5ms startup, SIMD JSON parsing, double-buffered TUI, zero-copy streaming — performance by design, not afterthought.
scorpiox code is written in pure C11 and compiled to fully static musl binaries. Every performance decision is deliberate — from memory allocation patterns to I/O multiplexing to the choice of JSON parser. The result: a 78-binary toolchain where the average binary is 850KB and the entire system runs in ~2MB RSS.
There is no runtime, no garbage collector, no JIT compiler, no interpreter layer. The binary you ship is the binary that runs — statically linked against musl libc, OpenSSL, libcurl, nghttp2/3, brotli, zstd, c-ares, and libidn2.
Zero external dependencies — config parsing, session management, conversation persistence, background tasks, metrics, JSON wrapper, TCP fetch, HTML stripping.
Provider abstraction, HTTP with SSE streaming, agentic loop, MCP client, state management — supports 8 LLM providers through a unified C interface.
Double-buffered cell-based terminal rendering, input handling, file explorer, bash terminal — minimal ANSI escape output via dirty-cell diffing.
Vendored yyjson — SIMD-accelerated C99 JSON parser. 3-10x faster than cJSON/jansson. In-situ parsing for zero-copy string access.
78 binaries, all statically linked with musl libc. No runtime dependencies — copy the binary, run it. The smallest is 32KB (scorpiox-otp), the largest is 4.2MB (scorpiox-server-email including full SMTP/IMAP stack).
| Metric | Value |
|---|---|
| Total binaries | 78 |
| Smallest binary | scorpiox-otp — 32 KB |
| Largest binary | scorpiox-server-email — 4,200 KB |
| Average size | 850 KB |
| Linking | Fully static (musl libc) |
| Runtime deps | None — zero .so files |
No garbage collector. No reference counting runtime. Memory is managed through a combination of static allocation, fixed-size pools, and bounded buffers — every allocation has a known maximum, making the memory footprint completely predictable.
Terminal rendering uses static SxCell front/back arrays allocated at compile time on WASM, avoiding heap fragmentation entirely.
8 max concurrent background tasks with 64KB rolling output buffers each. Zero dynamic pool resize — the pool size is a compile-time constant.
sx_strdup() aborts on allocation failure instead of returning NULL — prevents silent corruption propagating through the codebase.
HTTP response accumulation uses exponential growth (cap *= 2) — amortized O(1) append, minimizes realloc calls during streaming.
Per-task circular buffer — fixed 64KB window, oldest output discarded automatically. Bounded memory regardless of command output volume.
8KB static char queue for inter-thread message passing. Zero heap allocation for enqueued agent messages and callbacks.
2000-slot fixed-size message array — no linked list overhead. O(1) index access with predictable memory footprint.
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE for VM guest memory — demand-paged, zero-copy initialization, kernel manages physical backing.
Poll-based multiplexing with streaming callbacks. No event loop framework — just poll(2)/select(2) with tight timeouts and callback-driven data forwarding.
| Subsystem | I/O Strategy |
|---|---|
| Command exec | fork()+exec() with pipe, poll() at 100ms timeout for non-blocking output drain |
| PTY exec | forkpty()-based — child sees real terminal, disables output buffering in Python/Ruby/etc |
| SSE streaming | libcurl write_cb with real-time forwarding — on_data callback per chunk, zero buffering delay |
| Thunderbolt4 | Busy-poll mode with 4MB write buffers for low-latency raw Ethernet I/O |
| MCP | poll() with configurable timeout on stdio pipes to MCP server processes |
API request/response handling is JSON-heavy — every LLM API call serializes and parses large JSON payloads. scorpiox uses vendored yyjson, a SIMD-accelerated C99 parser that's 3-10x faster than cJSON or jansson.
11,224 LOC vendored. SIMD-accelerated parsing, in-situ (zero-copy) strings, immutable + mutable document model. YYJSON_WRITE_ALLOW_INVALID_UNICODE for robustness with malformed API responses.
Thin convenience layer — sx_yy_read(), sx_yy_write(), sx_yy_obj_add_raw() for Anthropic Messages API. No abstraction overhead.
sx_json_find_string_end_bounded() — operates on partial JSON buffers from SSE streams without full parse or allocation. Pure pointer arithmetic to find closing quotes in incomplete JSON fragments.
Double-buffered cell-based rendering. Every character position on screen is a cell with foreground color, background color, and attributes. Each frame diffs the front buffer against the back buffer — only changed cells emit ANSI escape sequences.
| Feature | Detail |
|---|---|
| Buffer size | SX_TERM_MAX_WIDTH=1024 × MAX_HEIGHT=512 (~12 bytes/cell) |
| Output buffer | 1MB native / 64KB WASM — batched flush |
| Dirty checking | cell_eq() diff — O(dirty_cells) not O(total_cells) |
| Cursor optimization | Skip sequential positions — minimize escape sequences |
| Attribute dedup | Only emit changed fg/bg/attr per cell |
| WASM adaptation | Static pre-allocated cell arrays, reduced buffer sizes |
Minimal threading — just enough to keep the UI responsive during API calls. Main thread handles input and rendering. Agent thread runs the agentic loop. A mutex protects the shared conversation array.
Input handling, display rendering, callback dispatch. Never blocks on network I/O.
Dedicated pthread for API calls. Runs agentic loop — tool calls, retries, conversation building. Mutex protects chat array.
PTY-based background command execution — 8 concurrent slots, per-task mutex, poll-based output collection.
Separate thread for cache keep-alive. Only sets a flag — never touches provider directly. Main loop picks up the flag.
Thread-safe linked-list event queue for C# P/Invoke — mutex-protected push/pop, non-blocking sx_recv().
sx_thread_wasm.h provides pthread stubs — agent runs synchronously. JSPI suspends C stack during async fetch.
C11 standard, -O2 optimization, security hardening flags that add negligible runtime cost. Cross-compilation to 7 platform targets from a single codebase.
| Platform | Static Dependencies |
|---|---|
| Linux | musl libc + curl + OpenSSL + nghttp2 + nghttp3 + brotli + zstd + c-ares + libidn2 |
| Windows | MinGW static curl + OpenSSL + zstd + nghttp2/3 + brotli + libssh2 |
| macOS | Mostly-static (system frameworks required) |
| Android | Static curl + mbedTLS |
| iOS | Static curl + mbedTLS |
| WASM | Emscripten + JSPI, reduced buffers (256×64 cells, 64KB output) |
Comparison against common runtime environments for AI coding assistants. All measurements are approximate — the point is order-of-magnitude differences, not micro-benchmarks.
| vs | Advantage |
|---|---|
| Node.js | 100x less memory (~2MB vs 200MB+), 50x faster startup, no GC pauses |
| Python | 50x less memory, instant startup, no interpreter overhead, no pip/venv |
| Go | 10x smaller binary (~850KB vs 8MB+), similar speed, no goroutine scheduler |
| Rust | Similar performance, faster compile times, simpler FFI for C# P/Invoke |
| Electron | 1000x less memory, 100x faster startup, zero Chromium overhead |
Single C codebase compiles to 7 platforms via preprocessor guards and build-time source selection. Each abstraction layer swaps the implementation at compile time — zero runtime dispatch overhead.
| Layer | Scope |
|---|---|
| sx_platform.h | Path separators, temp dirs, exe discovery, CA bundle, sx_fopen CLOEXEC |
| sx_http.h | HTTP — libcurl (native) vs Emscripten Fetch (WASM) |
| sx_pty.h | PTY — forkpty (Unix) vs ConPTY (Windows) vs stub (WASM) |
| sx_thread_wasm.h | Threading — pthreads (native) vs synchronous stubs (WASM) |
| sx_exec.h | Command execution — fork+exec (native) vs JS interop (WASM) |
| sx_term.h | Terminal — POSIX termios (Unix) vs Console API (Windows) vs xterm.js (WASM) |