Core Infrastructure Benchmarks

Read time 5 minutes
On this page

Detailed performance metrics for the Nalix core runtime, including connection management, session storage, packet registration, and concurrency gates.

Connection Hub

The ConnectionHub acts as the central registry for active socket connections.

MethodMeanErrorStdDevAllocated
GetConnection3.935 ns0.3706 ns0.4268 ns0 B
RegisterAndUnregister269.944 ns8.3769 ns8.9631 ns0 B

Behind the design

  • Lock-Free Indexing: The connection hub relies on high-performance concurrent collections and index arrays to handle concurrent registrations without global locks.
  • Fast Get Route: Looking up a session by its long identifier takes less than 4 nanoseconds (~3.9 ns), ensuring that session retrieval is not a bottleneck in the inbound message loop.

Connection Guard

The ConnectionGuard manages connection rate-limiting and connection-level IP blacklisting.

MethodMeanErrorStdDevAllocated
TryAccept_Allowed54.56 ns2.555 ns2.942 ns0 B
TryAccept_Blacklisted190.40 ns6.475 ns7.457 ns0 B

Behind the design

  • IP-Based Blacklist Fast Path: Blacklisted IPs are checked immediately using an optimized trie-like structure or hashset with absolutely zero allocations.
  • Quota Validation: Accepting a connection requires checking current concurrency limits and sliding-window request limits, executing in ~55 ns with zero heap allocations.

Session Store

The SessionStore maintains high-performance local user sessions.

MethodMeanErrorStdDevAllocated
StoreAndConsume154.7 ns5.87 ns6.76 ns48 B

Behind the design

  • Thread-Safe Session Maps: Uses lock-free lookup maps allowing simultaneous read operations. Adding and consuming session metadata is optimized for cache-friendly layouts.

Packet Registry

The PacketRegistry maps payload identifiers to concrete handler contracts.

MethodMeanErrorStdDevAllocated
TryDeserialize3.498 ns0.0349 ns0.0466 ns0 B

Behind the design

  • Zero-Allocation Deserialization Mapping: Mapping an incoming packet type identifier to its deserialization logic is fully pre-compiled and cached. A resolution path executes in under 4 ns with true zero heap allocation (0 B).

Dispatch Ready Queue

DispatchChannel<TPacket> hands a “connection has a packet ready” notification from the socket-completion callback to a dispatch worker once per message. That hand-off used System.Threading.Channels.Channel<T> (SingleReader = false, SingleWriter = false), even though the code only ever calls TryWrite/TryRead and never the async ReadAsync/WaitToReadAsync surface Channels exists to serve. Under that configuration, Channel<T> still takes a monitor lock on both write and read to keep its (unused) waiting-reader bookkeeping correct. It was replaced with a plain lock-free ConcurrentQueue<T>, which gives the same TryWrite/TryRead-shaped API without paying for machinery nothing calls.

MethodMeanRatioAllocated
Channel<T> write+read, single thread2.45 μs1.000 B
ConcurrentQueue<T> write+read, single thread0.89 μs0.380 B
Channel<T> write+read, producer/consumer threads149.20 ns / op1.000 B
ConcurrentQueue<T> write+read, producer/consumer threads24.96 ns / op0.173 B

End-to-end, exercising DispatchChannel<IPacket>.Push → TryClaim → TryDequeue → Release directly (the real per-message path):

ScenarioBeforeAfterChange
Single connection, no contention325.2 ns286.0 ns−12%
64 connections pushed concurrently, drained68.75 μs60.11 μs−12.6%

Behind the design

  • No feature paid for, no feature used: swapping the backing structure removed a lock acquisition on every enqueue/dequeue without changing behavior — the ready-queue never relied on Channel<T>’s blocking-reader semantics.
  • Numbers above vary run to run by up to ~20% on this shared 4-vCPU container; the ratio between the two implementations is the stable signal, not the absolute nanosecond figures.

Concurrency Gate & Throttling

Nalix uses a token bucket limiter and concurrency gates to prevent server overload and protect the hot-path.

Token Bucket Limiter

MethodMeanErrorStdDevP95Allocated
Evaluate86.72 ns2.303 ns2.652 ns88.85 ns0 B

Policy Rate Limiter

MethodMeanErrorStdDevP95Allocated
Evaluate106.7 ns3.48 ns4.00 ns111.7 ns0 B

Optimization Strategy

  • Atomic CAS (Compare-And-Swap) Loops: Throttling decisions are made using lock-free interlocked structures to perform atomic operations in nanoseconds.
  • Zero-Allocation Evaluation: The TokenBucket evaluation runs without object allocation (0 B) in ~87 ns, allowing rate-limiting checks directly on high-frequency packets.