Totodore / socketioxide

A socket.io server implementation in Rust that integrates with the Tower ecosystem and the Tokio stack.
https://docs.rs/socketioxide
MIT License
1.21k stars 52 forks source link

feat: namespace routing #333

Closed Totodore closed 3 months ago

Totodore commented 3 months ago

Motivation

Adding Namespace routing would allow to add a layer of multiplexing and also match the features of the official socket.io client.

Close issue #212.

Solution

Because I think that a regex based solution is way to slow and overkill for a simple router feature, the routing is implemented using the matchit crate. This allow to have a simple syntax for path parameters: /admin/{id}/board and even wildcards /admin/{*path}. One of the main drawbacks is the need of an adjacent buffer to store namespace because it is not possible to iterate over the path /values of the router. So currently this is using the slab crate from tokio to store namespace and the router only stores indexes.

Performance

Here are some benchmark results to compare previous Hashmap based implementation with the new based on Router + Slab: image

Todo

Totodore commented 3 months ago

After multiple experimentations and attempts to solve this problem I decided to report the following features for future PRs: