Architecture
Understanding the internals of SwiftX.
Architecture
SwiftX is designed to be high-performance and modular. It consists of several key components that work together to handle requests efficiently.
Core Runtime: SwiftXCore
The heart of SwiftX is the SwiftXCore runtime. This is an ultra-lean foundation that provides the essential primitives for non-blocking I/O and task management.
- Managed Worker Pool: A co-operative tasking system that moves away from traditional thread-per-request models.
- Custom Scheduler: Optimized for high-throughput and low-latency workloads.
The Routing Engine: RadixRouter
Routing in SwiftX is handled by a high-performance Radix Tree.
- O(k) Performance: The routing time is proportional only to the length of the path, not the number of routes.
- Pattern Matching: Supports static paths, path parameters (
:id), and wildcards (*).
Plugin System
SwiftX is entirely plugin-driven. Even core functionality like JSON handling or sessions can be implemented as plugins.
- Modularity: Keep your app lean by only including the plugins you need.
- Interoperability: Easily share plugins across different SwiftX projects.
Lifecycle of a Request
- Connection: A client connects to the server.
- Matching: The
RadixRoutermatches the request path to a handler. - Task Creation: A new
TaskContextis created in the Managed Worker Pool. - Execution: The handler is executed asynchronously.
- Response: The response is buffered and sent back to the client.
Concurrency and Async
SwiftX is built for Swift Concurrency. Handlers can be async and can safely call other async/await code without blocking the main worker threads.
