Memory management, I/O optimization, binary sizes, and benchmarks. Pure C delivers 2-5MB RSS, sub-5ms startup, and zero garbage collection pauses.
scorpiox code is written in C11 — a language with no runtime, no garbage collector, and direct control over every byte of memory. Every one of the 56 executables is statically linked: a single binary with zero dynamic library dependencies, zero interpreter startup cost, and deterministic memory behavior from the first instruction.
The build system (CMake 3.16+) compiles shared static libraries — sxutil, sxnet, sxui, sxterm — and each tool links only the libraries it needs. The result: small binaries, fast compilation, and no wasted code.
C11 standard · -O2 release optimization · -Wall -Wextra warnings · Static linking via SX_STATIC_LINK=ON · Platform conditionals eliminate dead code per target (Linux, macOS, Windows, ARM64, WASM).
Every memory allocation strategy in scorpiox code is chosen to avoid fragmentation, bound worst-case usage, and eliminate runtime overhead. No garbage collector. No reference counting. Just fixed buffers, ring buffers, and careful lifecycle management.
Terminal rendering on WASM uses static SxCell arrays — zero malloc at init, no fragmentation.
static SxCell front[256×64]
static SxCell back[256×64]
static char out_buf[64KB]
Config entries use fixed char[64] keys and char[512] values — zero heap allocation per entry.
SX_CONFIG_MAX_KEY = 64
SX_CONFIG_MAX_VAL = 512
Background tasks use a 64KB rolling buffer — fixed memory ceiling, old data evicted automatically.
SX_BGTASK_OUTPUT_MAX = 65536
max 8 tasks = 512KB total
Request builder uses 2x growth from 64KB initial — amortized O(1) append for API bodies.
DEFAULT_CAPACITY = 65536
GROWTH_FACTOR = 2
C11 stdatomic tracks every fork, popen, pipe — zero mutex contention for resource accounting.
8 atomic counters
atomic_fetch_add + CAS peak
Tool execution output capped at fixed buffer — prevents runaway tool output from consuming unbounded memory.
g_script_output[4096]
Atomic counters track every fork(), popen(), and pipe() open/close. At shutdown, sx_procmon_summary() reports any leaked resources. This catches resource leaks at the C level — something garbage-collected languages can't do.
The TUI uses a front/back cell buffer. On each frame, only changed cells emit ANSI escape sequences. Output is batched through a large write buffer and flushed once at the end.
Single write buffer for batched terminal output. WASM uses 64KB.
Maximum terminal grid size. WASM limited to 256×64 cells.
Rendering optimizations:
cell_eq() comparison skips unchanged cells — no redundant escape codesAll API request/response parsing uses yyjson — the fastest C JSON parser available. SIMD-optimized, in-situ parsing, immutable + mutable document APIs.
On modern CPUs with SIMD acceleration.
Fast output generation for API payloads.
YYJSON_WRITE_ALLOW_INVALID_UNICODE — prevents crashes from bad UTF-8 in tool outputwalk_path) for nested JSON queriessx_yy_obj_add_raw) — parse once, zero-copy insertSynchronous I/O with select() multiplexing for terminal input, email server clients (SMTP + IMAP + Submission), and DNS (UDP + TCP). The KVM runner uses poll() for non-blocking stdin.
56 executables are built from 7 shared static libraries. Each tool links only what it needs — the linker strips unused symbols, keeping binaries small.
| Library | Source Files | Purpose |
|---|---|---|
| sxutil | 22 files | Core utilities — config, log, exec, JSON, procmon, conversation |
| sxnet | 16 files | Network layer — HTTP, providers, agent, MCP, FRP, host |
| sxui | 7 files | TUI widgets — display, input, file explorer, bashterm |
| sxterm | 1 file | Terminal abstraction — double-buffered cell rendering |
| sxbridge | 1 file | Bridge module for IPC |
| yyjson | 1 file | High-performance JSON parser (vendored) |
| mbedtls | 60 files | TLS 1.2/1.3 — embedded crypto, no OpenSSL dependency |
scorpiox-config — single-file config tool, minimal library deps. Links only sxutil.
sx — main TUI. Links sxutil + sxnet + sxui + sxterm + mbedtls + yyjson + curl.
All binaries use -static linking (musl/glibc + libcurl + mbedTLS + yyjson). Zero dynamic linker overhead, no .so resolution at startup, works on any matching-architecture Linux without library compatibility issues.
Native: libcurl (static). WASM: Emscripten Fetch API. Unified sx_http.h interface — build selects implementation at compile time.
Multiple logical streams over single TCP+TLS connection. 12-byte header per frame, connection pooling, AES-128-CFB encrypted control.
YAMUX_MAX_STREAMS = 64
FRP_MAX_WORK_CONNS = 32
YAMUX_INITIAL_WINDOW = 256KB
mbedTLS vendored — TLS 1.2 + 1.3 support. No OpenSSL dependency. Smaller binary, faster compilation, predictable memory.
sendfile() kernel-space copy with streaming xxHash64 verification. Fallback path uses large-buffer read/send with SO_SNDBUF tuning.
Full DNS: UDP+TCP, split-horizon, upstream forwarding with response caching. A records, zone management CLI, TC flag for TCP retry.
SMTP + Submission + IMAP with STARTTLS, DKIM signing, maildir storage.
MAX_CLIENTS = 64 (per protocol)
BUFFER = 64KB per client
MAX_MSG = 25MB
Model Context Protocol — discovers tools from MCP servers, namespaces as mcp__<server>__<tool>.
SX_MCP_MAX_TOOLS = 512
tmux-compatible: Unix domain socket IPC, VT100/ANSI emulator per pane.
MAX_SESSIONS = 32
MAX_PANES = 64
VT_MAX_COLS = 512
Platform conditionals (SX_LINUX / SX_MACOS / SX_WINDOWS / __EMSCRIPTEN__) eliminate dead code per platform at compile time. Each target includes only the code paths it needs.
// WASM excludes:
pthread, fork, pty, procmon, bgtask, cache_keepalive
// Windows uses:
CriticalSection, _popen, CreateProcess
// Linux uses:
epoll-capable select, pty, unshare, KVM
// macOS:
mostly-static (Wl,-search_paths_first)
// Transient HTTP errors: 429, 500, 502, 503, 529
SX_RETRY_MAX_ATTEMPTS = 10
initial_delay = 1000ms
max_delay = 60000ms
backoff_factor = 2
Comparisons based on typical resource usage for AI coding assistants built with each technology stack:
~2-5MB RSS vs 200-500MB. 10× faster startup (<5ms vs 500ms+). No garbage collection pauses. Single static binary vs node_modules tree.
Instant startup vs interpreter boot. Compiled to native machine code. No pip dependencies or virtualenvs.
Static C vs Go runtime. Similar execution speed. No garbage collector. Finer-grained memory control with fixed buffers and rolling allocators.
Memory safety via careful C. Faster compilation. Simpler FFI. Broader embedded/WASM toolchain compatibility.
~2MB vs 200MB+. Instant startup vs Chromium boot. No bundled browser engine. 56 focused tools vs monolithic app.
Five platform targets, each with platform-specific adaptations:
Primary target. Full feature set: epoll, pty, unshare containers, KVM.
Same features as x86_64. Cross-compiled via CMake toolchain files.
Mostly-static linking. -Wl,-search_paths_first for library resolution.
CriticalSection for threading, _popen/CreateProcess for execution, native console APIs.
Static cell buffers (no malloc). 64KB output buffer. Emscripten Fetch API replaces libcurl. JS bridges for xterm.js terminal. No pthreads, no fork, no pty — single-threaded cooperative execution.