High-performance IPC and dynamic module loading toolkit for Rust
MemLink is a collection of high-performance Rust libraries for inter-process communication (IPC) and dynamic module loading. Built for low-latency, high-throughput applications, MemLink provides production-ready solutions for same-machine communication and plugin architectures.
| Capability | Crate | Use Case |
|---|---|---|
| Binary Protocol | memlink-protocol |
Message serialization and version negotiation |
| Shared Memory IPC | memlink-shm |
Ultra-low latency process communication |
| Dynamic Module Loading | memlink-runtime |
Plugin systems, hot-reloadable code |
| Module SDK | memlink-msdk |
Build memlink modules with ease |
| Proc Macros | memlink-msdk-macros |
Automatic code generation for modules |
Binary protocol definitions with MessagePack serialization and version negotiation.
Features:
- 📦 Fixed 32-byte message headers
- 🔢 Magic numbers and version constants
- 🏷️ Type aliases and enumerations
- ❌ Comprehensive error types
- 🔄 Version negotiation with feature flags
- ⚡ Zero-copy message parsing
- 🎯 Arena-backed slices
Performance:
Benchmark results from cargo bench -p memlink-protocol:
| Operation | Time | Throughput |
|---|---|---|
| Request serialize | 1.07 µs | 4.59 MiB/s |
| Response deserialize | 491 ns | 10.2 MiB/s |
| Error deserialize | 477 ns | 43.7 MiB/s |
Header as_bytes() |
46 ns | - |
Header from_bytes() |
37 ns | - |
Quick Start:
use memlink_protocol::{MessageHeader, MessageType, Request, Response};
use memlink_protocol::msgpack::MessagePackSerializer;
use memlink_protocol::serializer::Serializer;
// Create and serialize a request
let request = Request::new(
1,
memlink_protocol::Priority::Normal,
"calculator",
"add",
vec![1, 2, 3, 4],
);
let bytes = MessagePackSerializer.serialize_request(&request)?;
let parsed = MessagePackSerializer.deserialize_request(&bytes)?;📖 Documentation | 📦 crates.io | 📚 API Docs
Lock-free shared memory IPC with multi-priority message queues.
Features:
- 🔒 Lock-free ring buffer design
- 📊 Multi-priority queues (Critical, High, Low)
- ⚡ Futex-based signaling (Linux) / Event-based (Windows)
- 🛡️ Crash recovery and heartbeat monitoring
- 📈 Backpressure control
Performance:
| Payload | Latency (p50) | Throughput |
|---|---|---|
| Empty | 0.8 μs | 850K msg/sec |
| 64 bytes | 1.2 μs | 620K msg/sec |
| 1 KB | 2.8 μs | 280K msg/sec |
Quick Start:
use memlink_shm::buffer::{RingBuffer, Priority};
let rb = RingBuffer::new(256).unwrap();
rb.write_slot(Priority::High, b"Hello!").unwrap();
let (_, data) = rb.read_slot().unwrap();📖 Documentation | 📦 crates.io | 📚 API Docs
SDK for building memlink modules with automatic serialization, FFI exports, and panic isolation.
Features:
- 🎯
#[memlink_export]proc macro for easy method exports - 🔄 Automatic serialization/deserialization (MessagePack)
- 🛡️ Built-in panic isolation at FFI boundary
- 📊 Arena allocation for bounded memory management
- 🔗 Nested module-to-module calls
- 📈 Backpressure and deadline tracking
- 📝 Structured logging and metrics APIs
Performance:
Benchmark results from cargo bench -p memlink-msdk:
| Benchmark | Time | Throughput |
|---|---|---|
| Function call (empty) | 1.14 ns | 874.6 M/sec |
| Function call + serialization | 98.8 ns | 10.1 M/sec |
| Arena allocation (u64) | 2.41 ns | 414.8 M/sec |
| Arena alloc + init | 3.31 ns | 301.8 M/sec |
Quick Start:
use memlink_msdk::prelude::*;
#[memlink_export]
pub fn echo(ctx: &CallContext, input: String) -> Result<String> {
Ok(input)
}
#[memlink_export]
pub async fn async_echo(ctx: &CallContext, data: Vec<u8>) -> Result<Vec<u8>> {
Ok(data)
}
#[memlink_export]
pub fn use_arena(ctx: &CallContext) -> Result<u64> {
let x = ctx.arena().alloc::<u64>().ok_or(ModuleError::QuotaExceeded)?;
unsafe { std::ptr::write(x, 42); }
Ok(*x)
}📖 Documentation | 📚 API Docs | 🧪 Examples
Procedural macros for automatic code generation in memlink modules.
Features:
- 🎯
#[memlink_export]attribute macro for effortless method exports - ⚡ Compile-time FNV-1a method hash computation
- 🔄 Automatic MessagePack serialization/deserialization
- 🛡️ FFI boundary generation with built-in panic isolation
- 🔀 Support for both sync and async functions
- 🏷️ Custom method name attribution
Quick Start:
use memlink_msdk::prelude::*;
#[memlink_export]
pub fn echo(ctx: &CallContext, input: String) -> Result<String> {
Ok(input)
}
#[memlink_export]
pub async fn async_process(ctx: &CallContext, data: Vec<u8>) -> Result<Vec<u8>> {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
Ok(data)
}What the Macro Generates:
- Args struct for parameter serialization
- Wrapper function for serialization handling
- FFI export function with panic isolation
- Method dispatch table registration
📖 Documentation | 📚 API Docs | 🧪 Examples
Dynamic module loading framework for plugin architectures and hot-reloadable code.
Features:
- 🔌 Load
.so,.dll,.dylibat runtime - 🛡️ Panic isolation - module crashes don't affect host
- 🔥 Hot reload with zero downtime
- 📊 Prometheus-compatible metrics
- 🧵 Thread-safe concurrent module calls
- 📦 Multi-module management
Performance:
| Operation | Latency | Throughput |
|---|---|---|
| Module load | 92 μs | - |
| Method call | 210 ns | 4.7M calls/sec |
| Hot reload | 237 μs | - |
Quick Start:
use memlink_runtime::runtime::{Runtime, ModuleRuntime};
use memlink_runtime::resolver::ModuleRef;
let runtime = Runtime::with_local_resolver();
let handle = runtime.load(ModuleRef::parse("./plugin.so")?)?;
let result = runtime.call(handle, "process", b"input")?;📖 Documentation | 📚 API Docs | 📊 Benchmarks
memlink/
├── protocol/ # Binary protocol definitions
│ ├── src/ # Source code
│ ├── examples/ # Usage examples
│ ├── benches/ # Performance benchmarks
│ └── README.md # Detailed documentation
├── shm/ # Shared memory IPC library
│ ├── src/ # Source code
│ ├── examples/ # Usage examples
│ ├── benches/ # Performance benchmarks
│ └── README.md # Detailed documentation
├── runtime/ # Dynamic module loading
│ ├── src/ # Source code
│ ├── examples/ # Example modules and demos
│ ├── docs/ # ABI spec and benchmarks
│ └── README.md # Detailed documentation
├── msdk/ # Module SDK
│ ├── src/ # SDK source code
│ ├── tests/ # Integration tests
│ └── tests/integration.rs # All-in-one integration test suite
├── msdk-macros/ # Proc macros for msdk
│ └── src/ # Macro implementations
├── Cargo.toml # Workspace configuration
└── README.md # This file
[dependencies]
memlink-protocol = "0.1.0"
# With shared memory integration
memlink-protocol = { version = "0.1.0", features = ["shm"] }[dependencies]
memlink-shm = "0.1.3"[dependencies]
memlink-runtime = "0.1.2"[dependencies]
memlink-msdk = "0.1.2"[dependencies]
memlink-msdk-macros = "0.1.2"Note: memlink-msdk-macros is automatically included when you install memlink-msdk.
Ultra-low latency market data distribution between processes.
// SHM: Sub-microsecond tick data distribution
let buffer = RingBuffer::new(1024).unwrap();
buffer.write_slot(Priority::Critical, tick_data)?;Load user-created plugins without recompiling the host application.
// Runtime: Dynamic plugin loading
for plugin in std::fs::read_dir("./plugins")? {
runtime.load(ModuleRef::parse(plugin.path())?)?;
}Update rules and logic in production without downtime.
// Runtime: Zero-downtime reload
runtime.reload_with_config(handle, new_ref, reload_config)?;Fast communication between physics, rendering, and AI systems.
// SHM: Multi-priority message passing
physics_queue.write(Priority::High, physics_state);
render_queue.write(Priority::Low, render_commands);Same-machine service communication without network overhead.
// SHM: Replace network calls with shared memory
let response = shm_client.request(&request)?; // ~1 μs vs ~100 μs for TCP| Platform | memlink-protocol | memlink-shm | memlink-runtime |
|---|---|---|---|
| Linux | ✅ Tested | ✅ Tested | ✅ Tested |
| Windows | ✅ Tested | ✅ Tested | ✅ Tested |
| macOS | ✅ Tested | ✅ Tested | ✅ Tested |
- Rust 1.80 or later
- C compiler (for runtime module examples)
- Node.js 18+ (for runtime build scripts)
- WSL2 (for Linux builds on Windows)
# Build all crates
cargo build --workspace
# Build specific crate
cargo build -p memlink-shm
cargo build -p memlink-runtime# Run all tests
cargo test --workspace
# Test specific crate
cargo test -p memlink-protocol
cargo test -p memlink-shm
cargo test -p memlink-runtime
cargo test -p memlink-msdk
# Run integration tests only
cargo test --test integration -p memlink-protocol
cargo test --test integration -p memlink-msdk
# Run doc tests only
cargo test --doc -p memlink-protocol
cargo test --doc -p memlink-msdk# Run benchmarks
cargo bench -p memlink-protocol
cargo bench -p memlink-shm
cargo bench -p memlink-runtime
# Build test modules first (for runtime)
cd runtime/examples/modules/build
node build.js --linux# Format all code
cargo fmt --all
# Run clippy lints
cargo clippy --workspace --all-targets -- -D warnings
# Check msdk specifically
cargo clippy -p memlink-msdk
cargo clippy -p memlink-msdk-macros| Crate | Operation | Latency | Throughput |
|---|---|---|---|
| memlink-protocol | Request serialize | 1.07 µs | 4.59 MiB/s |
| memlink-protocol | Response deserialize | 491 ns | 10.2 MiB/s |
| memlink-protocol | Error deserialize | 477 ns | 43.7 MiB/s |
| memlink-protocol | Header as_bytes() |
46 ns | - |
| memlink-shm | Empty message | 0.8 μs | 850K/sec |
| memlink-shm | 1 KB payload | 2.8 μs | 280K/sec |
| memlink-msdk | Function call (empty) | 1.14 ns | 874.6 M/sec |
| memlink-msdk | Function call + serialization | 98.8 ns | 10.1 M/sec |
| memlink-msdk | Arena allocation | 2.41 ns | 414.8 M/sec |
| memlink-runtime | Module load | 92 μs | - |
| memlink-runtime | Method call | 210 ns | 4.7M/sec |
See individual crate documentation for detailed benchmarks:
- Zero-copy message serialization
- Multi-producer multi-consumer (MPMC) queues
- Persistent shared memory segments
- WebAssembly module support
- Module sandboxing with seccomp/AppContainer
- Automatic module discovery and loading
- Full
#[memlink_export]macro implementation - Zero-copy arena-based argument passing
- Built-in metrics and logging exporters
- Module hot-reload support
-
memlink-pipe- Cross-platform named pipe abstraction -
memlink-pool- Lock-free memory pool allocator
MemLink is licensed under the Apache License 2.0.
See LICENSE-APACHE for the full license text.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Implement your changes with tests
- Verify code quality:
cargo fmt --all cargo clippy --workspace --all-targets cargo test --workspace - Submit a pull request
- Follow Rust API Guidelines
- Add tests for new functionality
- Update documentation for API changes
- Include benchmarks for performance-sensitive code
| Resource | Link |
|---|---|
| Issues | GitHub Issues |
| Documentation | See individual crate README files |
| API Reference | docs.rs/memlink-shm, docs.rs/memlink-runtime |
| Discussions | GitHub Discussions |
- memmap2 - Cross-platform memory mapping
- libloading - Dynamic library loading
- dashmap - Concurrent hash maps
- Linux kernel futex implementation
- Lock-free SPSC ring buffer patterns
MemLink - Building fast, reliable Rust applications together.